Skip to content

Instantly share code, notes, and snippets.

@th0ma5w
Created February 9, 2016 21:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save th0ma5w/14f4aff79736a0fd00ac to your computer and use it in GitHub Desktop.
Save th0ma5w/14f4aff79736a0fd00ac to your computer and use it in GitHub Desktop.
(ns quiltest.core
(:require
[quil.core :as q]
[quil.applet :as qa]
)
(:import
[javax.swing JFrame])
)
(defn setup []
(q/smooth)
(q/frame-rate 480)
(q/background 255)
(q/no-stroke)
)
(defn draw []
(q/fill (q/random 255) (q/random 255) 0 (q/random 255))
(let [diam (q/random 100)
x (q/random (q/width))
y (q/random (q/height))]
(q/ellipse x y diam diam)))
(qa/defapplet example :setup setup :draw draw :size [200 200])
(.noLoop example)
(def sketch-surface (-> example .getSurface))
(def sketch-native (-> sketch-surface .getNative))
(def sketch-frame (-> sketch-native .getFrame))
(.setVisible sketch-frame false)
(def frame (JFrame. "Hello Frame"))
(.setSize frame 200 200)
(.setVisible frame true)
(.remove sketch-frame sketch-native)
(.add frame sketch-native)
(.loop example)

Description

[org.clojure/clojure "1.7.0"]
[quil "2.3.0"]

This is a non-ideal Quil sketch within a custom JFrame.

Essentially a lot of the older messier PApplet was broken out into various other classes. If you search for .getNative() you'll see a whole lot of places where it now lives. The .getNative appears to be available with a running sketch, however I could not simply create (.getNative (PApplet.)) as there seems to be quite a bit more other stuff going on now elsewhere is those other classes.

So this example blinks the main sketch frame momentarily, which is unfortunate.

But it proves that it can be done. I suspect that tracing the sketch initialization, and possibly recreating a lot of what happens up until the point of when the main graphics object is added to the frame may be key.

This will probably require a Java based wrapper class, and that may be easiest in order to cut & paste as much of the existing code as possible in order to make it easier perhaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment