Permalink
Browse files

Abstract applets out into their own namespace.

  • Loading branch information...
1 parent f087a0b commit 675f4880aa4fe57073524fe5d84961abb7720318 @technomancy committed Aug 28, 2009
Showing with 31 additions and 28 deletions.
  1. +2 −2 README.md
  2. +21 −2 src/sketchbook/applet.clj
  3. +8 −24 src/sketchbook/pop.clj
View
@@ -10,8 +10,8 @@ Then run with:
$ corkscrew repl
Clojure 1.0.0--SNAPSHOT
- user=> (require 'sketchbook.bio)
- user=> (sketchbook.bio/run)
+ user=> (require 'sketchbook.pop)
+ user=> (sketchbook.pop/run)
To install corkscrew, see http://github.com/technomancy/corkscrew
@@ -1,4 +1,23 @@
(ns sketchbook.applet
(:use rosado.processing)
- (:import (javax.swing JFrame JLabel JTextField JButton))
- (:import (processing.core PApplet)))
+ (:import (javax.swing JFrame)))
+
+(defmacro defapplet
+ [name title setup draw width height]
+ `(do
+ (def ~name
+ (proxy [processing.core.PApplet] []
+ (setup []
+ (binding [*applet* ~'this]
+ (size ~width ~height)
+ (~setup)))
+ (draw []
+ (binding [*applet* ~'this]
+ (~draw)))))
+ (defn ~(symbol (str "run-" name)) []
+ (.init ~name)
+ (doto (JFrame. ~title)
+ (.setSize ~width ~height)
+ (.add ~name)
+ (.pack)
+ (.show)))))
@@ -1,39 +1,23 @@
(ns sketchbook.pop
- (:use [rosado.processing])
- (:import (processing.core PApplet))
- (:import (javax.swing JFrame JLabel JTextField JButton)))
+ (:use [sketchbook.applet]
+ [rosado.processing]))
-(def z (atom 0.0))
+(def generation (atom 0.0))
(defn setup []
- (size 510 510)
(no-stroke)
(framerate 5))
(defn draw []
- (background-float 255)
- (swap! z inc)
+ (swap! generation inc)
(dotimes [x 5]
(dotimes [y 5]
- (fill-float (* 255 (noise x y @z)))
+ (fill-float (* 255 (noise x y @generation)))
(rect (+ (* x 100) 10)
(+ (* y 100) 10)
90 90))))
-(def p5-applet
- (proxy [PApplet] []
- (setup []
- (binding [*applet* this]
- (setup)))
- (draw []
- (binding [*applet* this]
- (draw)))))
+(defapplet popp "Synthpop-inspired Jams"
+ setup draw 510 510)
-(.init p5-applet)
-
-(defonce swing-frame
- (doto (JFrame. "Processing with Clojure")
- (.setSize 510 510)
- (.add p5-applet)
- (.pack)
- (.show)))
+(run-popp)

0 comments on commit 675f488

Please sign in to comment.