简体   繁体   中英

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

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))

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))

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM