forked from rosado/clj-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update example2.clj to use defapplet macro.
- Loading branch information
1 parent
dffaec5
commit 32f26ee
Showing
2 changed files
with
32 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
rosado.processing.jar | ||
rosado.processing.jar | ||
lib/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |