running multiple exported processing sketches from quil

29 views
Skip to first unread message

b...@benswift.me

unread,
Oct 13, 2016, 5:24:36 AM10/13/16
to clj-processing
Hi folks

I've got a bunch of Processing "scene" sketches which I want to run/manage from one "master" sketch. I export all the scenes to java (they are subclasses of PApplet) and can create instances in clojure like so

(ns gallery-manager.core
 
(:import MySketchOne MySketchTwo)
 
(:require [quil.core :as q]))

;; this constructor works fine
(def sketch1 (MySketchOne.))

However, I can't figure out the way to run this sketch through quil. `defsketch` et.al. seem to all create the applet themselves, rather than taking an existing applet, and just calling `runSketch` causes a crash (I guess because the window setup stuff isn't set up properly).

Any advice on whether this is possible, and the best way to do it?

Nikita Beloglazov

unread,
Oct 13, 2016, 12:28:44 PM10/13/16
to clj-processing
Hi Ben

You're right, that quil doesn't have methods to launch PApplet instances created outside of it. To do it you'll have to fallback to java interop. I think following might work:

(defn create-and-run []
  (let [sketch (MySketchOne.)]
    (PApplet/runSketch 
      (into-array String [])
      sketch)))

It uses runSketch static method you mentioned. And I think it should work. At least that's how Quil launches sketches. I hope helps.

Thanks,
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/d/optout.

b...@benswift.me

unread,
Oct 13, 2016, 8:37:28 PM10/13/16
to clj-processing
Thanks for the reply. Yep, I tried that, but calling create-and-run crashes (stacktrace below).

I've put my minimal nonworking example into a GH repo if anyone's interested.

Part of the problem is that I don't *really* know how the PApplet lifecycle works, and so it seems suspicious that it's not creating a window or anything.

Anyway, thanks for all your help. If we do find a way to make it working I'm happy to do the work to get it upstream (with examples).

user=> (require 'exported-sketch-example.core)
Usage: PApplet [options] <class name> [sketch args]
See the Javadoc for PApplet for an explanation.
SocketException The transport'
s socket appears to have lost its connection to the nREPL server
Exception in thread "Thread-3" clojure.lang.ExceptionInfo: Subprocess failed {:exit-code 1}
    at clojure
.core$ex_info.invokeStatic(core.clj:4617)
    at clojure
.core$ex_info.invoke(core.clj:4617)
    at leiningen
.core.eval$fn__5732.invokeStatic(eval.clj:264)
    at leiningen
.core.eval$fn__5732.invoke(eval.clj:260)
    at clojure
.lang.MultiFn.invoke(MultiFn.java:233)
    at leiningen
.core.eval$eval_in_project.invokeStatic(eval.clj:366)
    at leiningen
.core.eval$eval_in_project.invoke(eval.clj:356)
    at leiningen
.repl$server$fn__11838.invoke(repl.clj:243)
    at clojure
.lang.AFn.applyToHelper(AFn.java:152)
    at clojure
.lang.AFn.applyTo(AFn.java:144)
    at clojure
.core$apply.invokeStatic(core.clj:646)
    at clojure
.core$with_bindings_STAR_.invokeStatic(core.clj:1881)
    at clojure
.core$with_bindings_STAR_.doInvoke(core.clj:1881)
    at clojure
.lang.RestFn.invoke(RestFn.java:425)
    at clojure
.lang.AFn.applyToHelper(AFn.java:156)
    at clojure
.lang.RestFn.applyTo(RestFn.java:132)
    at clojure
.core$apply.invokeStatic(core.clj:650)
    at clojure
.core$bound_fn_STAR_$fn__4671.doInvoke(core.clj:1911)
    at clojure
.lang.RestFn.invoke(RestFn.java:397)
    at clojure
.lang.AFn.run(AFn.java:22)
    at java
.lang.Thread.run(Thread.java:744)
    clojure
.tools.nrepl.transport/bencode/fn--10199/fn--10200 (transport.clj:95)
    clojure
.tools.nrepl.transport/bencode/fn--10199 (transport.clj:95)
    clojure
.tools.nrepl.transport/fn-transport/fn--10171 (transport.clj:42)
    clojure
.core/binding-conveyor-fn/fn--4676 (core.clj:1938)
    java
.util.concurrent.FutureTask.run (FutureTask.java:266)
    java
.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
    java
.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    java
.lang.Thread.run (Thread.java:744)
Bye for now!

Nikita Beloglazov

unread,
Oct 14, 2016, 1:34:11 AM10/14/16
to clj-processing
Ok, I found the error. Apparently you cannot pass empty array to runSketch. It requires at least 1 argument. So you can pass sketch title:

(defn create-and-run []
  (let [sketch (MySketchOne.)]
    (PApplet/
runSketch 
      (into-array String ["SketchTitle"])
      sketch)))
There is another problem though. By default, when you close instance of PApplet it kills jvm. So you in your java file that defines your custom applet you need to override exitActual() method to do nothing. 

Reply all
Reply to author
Forward
0 new messages