4
votes

I would like to create a command line application that generates jpg images using Quil. I plan to write a couple of generic image processing functions to mix and match (some fn drawing shapes and some manipulating the pixel array).

A simple example of what I would like to do is create one function that draws a circle then a second function that applies a dither algorithm to the pixel array.

(defn draw-circle [x y] ...) ;; e.g. internally uses Quil draw functions.

(defn apply-dither [pixels] ...) ;; e.g. internally uses Quil color functions on the pixels array.

(defn draw []
(draw-circle 100 100)
(apply-dither (pixels))
...)

(defsketch sketch
:draw draw)

What is causing me a bit of grief is all Quil functions seems to only run within a sketch macro. This means that my own functions using the Quil functions internally in turn cannot be directly called (must be called from a draw function triggered by a sketch macro), making debugging and running them individually from the repl harder/impossible.

How do I go about creating and debugging such generic functions? Am I stuck having sketch call functions on my behalf or is there another way?

There is also the possibility that Quil isn't the right tool for my project. I'm considering directly using java / processing classes.

My development environment is Emacs + Cider.

Thanks

1

1 Answers

1
votes

I've created a series of quil sketches that run from the command line at https://github.com/rogerallen/qeom

I developed & iterated within emacs+cider and just recompiled the draw function to see the results update live in the sketch window.

I used an atom (defonce dump-image-count (atom 1)) to control when the draw function would save an image:

(defn draw []
   ...
   (when (> @dump-image-count 0)
      (save-frame "q007-dump-####.png")
      (swap! dump-image-count dec)))

Hope this helps.