Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(use '(incanter core processing))
;; simple interactive Processing example taken from website:
;; set up variable references to use in the sketch object
(let [radius (ref 50.0)
X (ref nil)
Y (ref nil)
nX (ref nil)
nY (ref nil)
delay 16
;; define a sketch object (i.e. PApplet)
sktch (sketch
;; define the setup function
(setup []
(doto this
(size 200 200)
(stroke-weight 10)
(framerate 15)
(ref-set X (/ (width this) 2))
(ref-set Y (/ (width this) 2))
(ref-set nX @X)
(ref-set nY @Y)))
;; define the draw function
(draw []
(ref-set radius (+ @radius (sin (/ (frame-count this) 4))))
(ref-set X (+ @X (/ (- @nX @X) delay)))
(ref-set Y (+ @Y (/ (- @nY @Y) delay))))
(doto this
(background 125) ;; gray
(fill 0 121 184)
(stroke 255)
(ellipse @X @Y @radius @radius)
;(save "proc_example1.png")
;; define mouseMoved function (mouseMoved and mouseDraw
;; require a 'mouse-event' argument unlike the standard Processing
;; methods)
(mouseMoved [mouse-event]
;; mouse-x and mouse-y take the mouse-event as an argument
(ref-set nX (mouse-x mouse-event))
(ref-set nY (mouse-y mouse-event)))))]
;; use the view function to display the sketch
(view sktch :size [200 200]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment