A 2D graphics library for clojure using mindra -- a cli for diagrams and gloss.
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"}
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.
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.
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 |
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
D. Simple animation with event handling
circles.mov
Copyright © 2022 Amit Shrestha
This program and the accompanying materials are made available under MIT License