Skip to content

Commit

Permalink
Update example2.clj to use defapplet macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Aug 29, 2009
1 parent dffaec5 commit 32f26ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 44 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rosado.processing.jar
rosado.processing.jar
lib/*
73 changes: 30 additions & 43 deletions examples/example2.clj
Original file line number Diff line number Diff line change
@@ -1,56 +1,43 @@
;; processing example

(ns p5-example2
(:use rosado.processing)
(:import (javax.swing JFrame JLabel JTextField JButton))
(:import (processing.core PApplet)))

(ns example2
(:use [rosado.processing]
[rosado.processing.applet]))

;; here's a function which will be called by Processing's (PApplet)
;; draw method every frame. Place your code here. If you eval it
;; interactively, you can redefine it while the applet is running and
;; see effects immediately

(defn fancy-draw
(defn draw
"Example usage of with-translation and with-rotation."
[dst]
(background-float 125)
(stroke-float 10)
(fill-float (rand-int 125) (rand-int 125) (rand-int 125))
(with-translation [(/ 200 2) (/ 200 2)]
(with-rotation [QUARTER_PI]
(begin-shape)
(vertex -50 50)
(vertex 50 50)
(vertex 50 -50)
(vertex -50 -50)
(end-shape CLOSE)))
[]
(background-float 125)
(stroke-float 10)
(fill-float (rand-int 125) (rand-int 125) (rand-int 125))
(with-translation [(/ 200 2) (/ 200 2)]
(with-rotation [QUARTER_PI]
(begin-shape)
(vertex -50 50)
(vertex 50 50)
(vertex 50 -50)
(vertex -50 -50)
(end-shape CLOSE)))
(filter-kind INVERT)
(framerate 10))

;; below, we create an PApplet proxy and override setup() and draw()
;; methods. Then we put the applet into a window and display it.

(def p5-applet
(proxy [PApplet] []
(setup []
(binding [*applet* this]
(size 200 200)
(smooth)
(no-stroke)
(fill 226)
(framerate 10)))
(draw []
(binding [*applet* this]
(fancy-draw this)))))

(.init p5-applet)

(def swing-frame (JFrame. "Processing with Clojure"))
(doto swing-frame
(.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)
(.setSize 200 200)
(.add p5-applet)
(.pack)
(.show))
(defn setup []
"Runs once."
(smooth)
(no-stroke)
(fill 226)
(framerate 10))

;; Now we just need to define an applet:

(defapplet example2 "An example."
setup draw 200 200)

(run-example2)

;; (stop-example2)

0 comments on commit 32f26ee

Please sign in to comment.