Liking cljdoc? Tell your friends :D

Clojars Project cljdoc badge CircleCI stability-alpha

Note: Alpha status. Each new version might have breaking changes.

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-clj "0.0.4"]

deps.edn

org.clojars.rorokimdim/mindra-clj {: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)))

(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

https://user-images.githubusercontent.com/929342/160046861-e0f61455-adc0-48c8-8882-ddef80f55d18.mov

source (images obtained from dumbmanex.com)

C. Snowballer animation

https://user-images.githubusercontent.com/929342/160048147-2fc39ea7-feb1-409e-adb1-288a869fe4ff.mov

source

D. Simple animation with event handling

https://user-images.githubusercontent.com/929342/160048948-8acfbca6-63c7-4cfe-9adb-e3418b414807.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

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close