how can I write a boot script to load a quil/processing sketch?

164 Views Asked by At

I have boot working with other examples, but im trying to use it with quil/Processing. I wrote this simple script and tried to run it, but all it does is launches a Java Applet window then immediately closes. There are no error logs for me to debug.

#!/usr/bin/env boot
(set-env! :dependencies '[[quil "2.6.0"]])
(require '[quil.core :as q])
(defn setup []
  (q/background 111 111 111 )  )
(defn -main  [& args]
  (q/defsketch my-art
  :size [800 800]
  :setup setup))
3

There are 3 best solutions below

0
jas On

This code works, but its not the right answer as it uses a sleep. are there better ways to do this without a sleep?:

#!/usr/bin/env boot
(set-env! :dependencies '[[quil "2.6.0"]])
(require '[quil.core :as q])

(defn draw []
  (println "in draw")
  (q/background 111 111 111 )  )

(defn -main  [& args]
  (println "starting")
  (q/defsketch my-art
    :size [800 800]
    :draw draw)
  (Thread/sleep 5000))
0
juan.facorro On

After the window is created, the main thread has probably nothing else to do and the JVM exits. You can confirm this by adding a (Thread/sleep 5000) after the call to q/defsketch.

I took a quick look at quil's code. defsketch returns an instance of quil.Applet, which implements processing.core.PApplet. Although PApplet uses AWT under the covers it doesn't extend or implement any AWT classes, it internally creates other Processing classes.

The simplest way to keep the window open would be to read from console with (.read System/in) after creating the sketch. There might be other, fancier approaches though.

0
flyboarder On

Generally you would want to convert your example to a boot task, then call your quill task + watch task to prevent the boot pipeline from exiting.

ie. boot watch quill

This will prevent boot from exiting once your quill task finishes, however you may need to implement additional control flows depending on how quill functions.