[英]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. 我已经开始使用其他示例,但我试图将它与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. 我编写了这个简单的脚本并尝试运行它,但它只是启动一个Java Applet窗口然后立即关闭。 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. 创建窗口后,主线程可能没有其他任何操作,JVM退出。 You can confirm this by adding a (Thread/sleep 5000)
after the call to q/defsketch
. 您可以通过在调用q/defsketch
之后添加(Thread/sleep 5000)
来确认这q/defsketch
。
I took a quick look at quil
's code. 我快速浏览了一下quil
的代码。 defsketch
returns an instance of quil.Applet
, which implements processing.core.PApplet . defsketch
返回的实例quil.Applet
,它实现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. 虽然PApplet
使用AWT,它不会扩展或实现任何AWT类,但它在内部创建了其他Processing类。
The simplest way to keep the window open would be to read from console with (.read System/in)
after creating the sketch. 保持窗口打开的最简单方法是在创建草图后从控制台读取(.read System/in)
。 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. 通常,您希望将示例转换为启动任务,然后调用您的quill任务+监视任务以防止启动管道退出。
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. 这将阻止在您的主轴任务完成后退出,但是您可能需要根据主轴的功能实现其他控制流程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.