Skip to content

A 2D Graphics library for clojure using diagrams and gloss.

License

Notifications You must be signed in to change notification settings

rorokimdim/mindra-clj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clojars Project cljdoc badge

mindra-clj

A 2D graphics library for clojure using mindra -- a cli for diagrams and gloss.

Installation

A. Install mindra from mindra-binary

If you encounter any problems, please file an issue.

B. Set up a clojure project

Leiningen/Boot

[org.clojars.rorokimdim/mindra "0.0.4"]

deps.edn

org.clojars.rorokimdim/mindra {:mvn/version "0.0.4"}

Usage

mindra has two set of functions (APIs): one for diagrams and another for gloss. They are not intended to be used together: when creating a gloss picture, we should avoid using functions from the diagrams namespace, and vice versa.

Try drawing a simple circle in a repl:

A circle using Diagrams

(require '[mindra.core :refer [diagram->svg]])
(require '[mindra.diagrams :as md])

(defn draw-circle [radius]
  (let [svg (diagram->svg (md/circle radius))]
    (spit "circle.svg" svg)))

; Writes to "circle.svg" file.
; For other formats, try mindra.core/diagram->file.
; For displaying the image in a gui window, try mindra.core/show-diagram
(draw-circle 100)

A circle using Gloss

(require '[mindra.core :refer [gloss-draw]])
(require '[mindra.gloss :as mg])

(defn draw-circle [radius]
  (let [picture (mg/circle radius)]
    (gloss-draw picture)))

(draw-circle 100)

Hit ESC to close the window. See default-key-bindings.

Next, checkout the examples.

Q/A

A. How does it compare with library x?

tldr; I don't know yet or I may not have tried it.

I wanted something like htdp/image, 2htdp/universe for clojure, without the pain (and required skillset) of building it myself. Leveraging diagrams and gloss, which I was already familiar with, seemed like the easiest solution.

B. Why is the graphics not as smooth as in library x?

mindra inherits all the tradeoffs made by diagrams and gloss, and all their deficiencies. It also has quirks of its own and, at this stage, probably plenty of bugs too.

However, if you observe poorer graphics with mindra compared to diagrams/gloss, please file an issue.

C. Will it support feature x?

Please file an issue/feature-request.

D. Babashka, GraalVM?

As long as mindra binary is available, this library is expected to work in both! If it doesn't, please file an issue.

Examples

Diagrams

SVGs can be created using diagrams library. Please check out diagrams.github.io to learn more.

Only a small subset of the features provided by diagrams is supported at this time.

source source source
source source source
source source source
source source source

Gloss

Please check out gloss.ouroborus.net to learn more.

A good subset of the features provided by gloss is already supported.

A. Basic drawing

source (images used obtained from dumbmanex.com)

B. Hilbert curve animation

play-hilbert-pattern.mov

source (images obtained from dumbmanex.com)

C. Snowballer animation

snowballer.mov

source

D. Simple animation with event handling

circles.mov

source

Credits

  1. Clojure
  2. Diagrams and Gloss
  3. All of these libraries

License

Copyright © 2022 Amit Shrestha

This program and the accompanying materials are made available under MIT License

About

A 2D Graphics library for clojure using diagrams and gloss.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published