Skip to content

Instantly share code, notes, and snippets.

@mharju
Created August 11, 2012 11:53
Show Gist options
  • Save mharju/3324018 to your computer and use it in GitHub Desktop.
Save mharju/3324018 to your computer and use it in GitHub Desktop.
Testing quil
(use 'quil.core)
(def draw-state (atom :draw))
(defn setup []
(background 11 11 11)
(smooth))
(defn my-random [min max]
(let [delta (- max min)]
(+ min (* (rand) delta))))
(defn delta [theta]
(my-random -50 50))
(defn m [theta]
(+ theta (delta theta)))
(defrecord Walker [position stroke angle])
(defn draw-walker [a-walker]
(let [pos-atom (:position a-walker)
c (m (:angle a-walker))
r 10
ellipse-radius (* 200 (noise (frame-count) 100))
x (+ (* r (cos c)) (first @pos-atom))
y (+ (* r (sin c)) (second @pos-atom))]
(apply stroke (:stroke a-walker))
(ellipse x y ellipse-radius ellipse-radius)
(assoc a-walker :angle c)
(if (or
(> x (width)) (> y (height))
(< x 0) (< y 0))
(swap! pos-atom (fn [n] [(my-random 0 (width)) (my-random 0 (height))]))
(swap! pos-atom (fn [n] [x y])))))
(def walkers [(Walker. (atom [100 100]) '(255 66 189 32) 0.0)
(Walker. (atom [200 200]) '(28 252 252 32) 0.0)
(Walker. (atom [300 300]) '(252 28 28 32) 0.0)])
(defn draw []
(case @draw-state
:draw (do
(when (= (mod (frame-count) 1000) 0)
(reset! draw-state :fade))
(no-fill)
(stroke-weight 1)
(doseq [walker walkers] (draw-walker walker)))
:fade (do
(if (= (mod (frame-count) 100) 0)
(reset! draw-state :draw)
(display-filter :blur)))))
(defsketch example
:size [800 400]
:draw draw
:setup setup
:title "Mighty project")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment