standalone quil app?

228 views
Skip to first unread message

John Gabriele

unread,
Jan 28, 2013, 10:58:44 AM1/28/13
to clj-pro...@googlegroups.com
Hi,

Can I use quil to create a standalone app? That is, after `lein new
my-quil-app`, what would have to go into my -main?

I'd like to be able to create a standalone jar and run it in the usual
way (`lein uberjar`, `java -jar my-quil-app-0.1.0-standalone.jar arg1
arg2`).

If I copy what's in the readme (the `setup`, `draw`, and `defsketch
example`) as-is into my src/my_quil_app/core.clj, and leave the
default -main alone; then do `lein run`, the app runs, and also of
course prints "Hello, World!", but closing the window leaves the app
still running (I need to ^c to quit it).

Thanks,
---John

Nikita Beloglazov

unread,
Jan 28, 2013, 5:07:41 PM1/28/13
to clj-pro...@googlegroups.com
Hi John,

If you want to create a standalone app you shouldn't use defsketch. defsketch is good for development, for playing with quil. You should use sketch instead. Here is an example. Actually you can also use defsketch, but it MUST be inside other function. If it will be in outer level (like in quils README) then you won't be able to create uberjar using lein uberjar.

About the problem with running JVM after you close window. quil works now in such way that JVM is not killed after you close window. It is very convenient during development because if JVM is killed after you close window - you'll need to start new repl every time you want to run new sketch. One of unreleased new features is :on-close handler that gets invoked once you close window. You can use it to stop JVM. But until new version of quil is released I can propose following hack: sketch function returns and instance of PApplet - class that extends java.applet.Applet. This applet actually placed inside JFrame. We can retrieve this JFrame using getParent method and change default close operation. It is set to DISPOSE_ON_CLOSE by default in order to prevent JVM stop. But we want JVM to stop so we need to change it to EXIT_ON_CLOSE. I implemented method exit-on-close that takes applet returned by sketch and sets default close operation. Check it.

Thank you,
Nikita Beloglazov

jmg...@gmail.com

unread,
Jan 29, 2013, 10:09:20 AM1/29/13
to clj-pro...@googlegroups.com
Thanks so much for the info, and for the hack, Nikita! Works great.

Looking forward to the arrival of the :on-close addition to quil.

---John

jmg...@gmail.com

unread,
Mar 21, 2013, 10:27:54 AM3/21/13
to clj-pro...@googlegroups.com
Hm. Getting back to this, the .getParent hack no longer appears to be working for me. I get:

~~~
$ lein run
Exception in thread "main" java.lang.IllegalArgumentException: No matching field found: getParent for class quil.core$sketch
    at clojure.lang.Reflector.getInstanceField(Reflector.java:271)
    at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:300)
    at my_quil_app.core$exit_on_close.invoke(core.clj:30)
    at my_quil_app.core$_main.doInvoke(core.clj:43)
{snip}
~~~

Same result with both Clojure 1.4.0 and 1.5.1. This is using quil 1.6.0. (Code at <https://gist.github.com/uvtc/5213415>.)

jmg...@gmail.com

unread,
Mar 21, 2013, 10:32:23 AM3/21/13
to clj-pro...@googlegroups.com
On Thursday, March 21, 2013 10:27:54 AM UTC-4, jmg...@gmail.com wrote:
Hm. Getting back to this, the .getParent hack no longer appears to be working for me. I get:

{snip}

BTW, this is with OpenJDK 7 on Xubuntu 12.04.

Nikita Beloglazov

unread,
Mar 21, 2013, 11:04:13 AM3/21/13
to clj-pro...@googlegroups.com

Hi

Your exit-on-close is wrong. You're using q/sketch in it, it's wrong. You should use just sketch.  No q/, because q/sketch is a quil function while sketch is a function argument.

Nikita

--
You received this message because you are subscribed to the Google Groups "clj-processing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clj-processin...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

jmg...@gmail.com

unread,
Mar 21, 2013, 12:38:07 PM3/21/13
to clj-pro...@googlegroups.com
On Thursday, March 21, 2013 11:04:13 AM UTC-4, Nikita Beloglazov wrote:

Hi

Your exit-on-close is wrong. You're using q/sketch in it, it's wrong. You should use just sketch.  No q/, because q/sketch is a quil function while sketch is a function argument.


Ooof! Thanks, Nikita!

 
Reply all
Reply to author
Forward
0 new messages