Permalink
Browse files

Added myu sketch.

  • Loading branch information...
1 parent 7f9c67a commit 6313522c8127a7d896e3d50347ec31b55484c411 @technomancy committed Aug 30, 2009
Showing with 46 additions and 0 deletions.
  1. +46 −0 src/sketchbook/myu.clj
View
@@ -0,0 +1,46 @@
+(ns sketchbook.myu
+ (:use [rosado.processing]
+ [rosado.processing.applet]))
+
+(defn frame-count [] (.frameCount *applet*))
+
+(def last-vortex (atom [0 0]))
+(def vortex (atom [0 0]))
+(def vortex-size 20)
+(def vortex-velocity (atom [10 10]))
+
+(defn sine-frame []
+ (sin (/ (frame-count) 5.0)))
+
+(defn bounce! []
+ (when (or (> (first @vortex) (.getWidth *applet*)) (neg? (first @vortex)))
+ (swap! vortex-velocity (fn [[x y]] [(- x) y])))
+ (when (or (> (last @vortex) (.getHeight *applet*)) (neg? (last @vortex)))
+ (swap! vortex-velocity (fn [[x y]] [x (- y)]))))
+
+(defn move! []
+ (bounce!)
+ (swap! vortex #(map + % @vortex-velocity)))
+
+(defn draw-vortex
+ ([alpha]
+ (draw-vortex alpha @vortex))
+ ([alpha [x y]]
+ (fill 255 alpha)
+ (ellipse x y vortex-size vortex-size)))
+
+(defn setup []
+ (background-float 0)
+ (smooth)
+ (no-stroke)
+ (framerate 10))
+
+(defn draw []
+ (move!)
+ (draw-vortex (* 150 (/ (+ (sine-frame) 1) 2))))
+
+(defapplet myu "Something vaguely birdlike"
+ setup draw 800 600)
+
+;; (run-myu)
+;; (stop-myu)

0 comments on commit 6313522

Please sign in to comment.