public
Last active — forked from samaaron/gist:2885344

Dancer with colors and motion paths

  • Download Gist
gistfile1.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
(ns examples.rotating-spheres
(:use [quil.core]))
 
(defn rand-circle-coords []
(let [max-x (* 2 (width))
max-y (* 2 (height))
max-z 800]
[(random (- max-x) max-x) (random (- max-y) max-y) (random (- max-z) max-z)]))
 
(def circle-coords
(repeatedly 80 rand-circle-coords))
 
(defn music-video
[]
[(cos (radians (* 0.5 (frame-count))))
(* 0.1 (sin (radians (* 0.12 (Math/pow (frame-count) 1.3)))))
(* 1 (sin (radians (* 0.12 (Math/pow (frame-count) 1.3)))))])
 
(defn momentary-collapse
[]
[(cos (radians (* 0.5 (frame-count))))
(* 0.1 (tan (radians (* 0.5 (frame-count)))))
(sin (radians (* 0.12 (Math/pow (frame-count) 1.3))))])
 
(defn slow-flip
[]
[(cos (radians (* 0.5 (frame-count))))
0.1
(sin (radians (frame-count)))])
 
(defn osc-left-right
[]
[(cos (radians (frame-count)))
0.1
(sin (radians (frame-count)))])
 
(defn there-and-back
[]
[(cos (radians (frame-count)))
0.1
(* (Math/pow (radians (frame-count)) 0.28)
(sin (radians (frame-count))))])
 
(defn twirl
[]
[(cos (radians (frame-count)))
0.1
(sin (radians (frame-count)))])
 
(defn choose
[s]
(nth s (rand-int (count s))))
 
(defn setup []
(background 20)
(smooth)
(set-state! :animator (atom twirl)))
 
(defn color-rotator
[]
(fill (+ 128 (* 128 (sin (radians (frame-count)))))
(+ 128 (* 128 (cos (radians (Math/pow (frame-count) 1.2)))))
(+ 128 (* 128 (tan (radians (frame-count))))))
(stroke (+ 108 (* 100 (sin (radians (frame-count)))))))
 
(defn draw []
(background 20)
(color-rotator)
(sphere-detail 10)
(doseq [coords circle-coords]
(with-translation coords
(sphere 10)))
 
(when (zero? (mod (frame-count) 500))
(reset! (state :animator) (choose [twirl there-and-back osc-left-right
slow-flip momentary-collapse music-video])))
 
(let [radius 1000
[xpos ypos zpos] (@(state :animator))
xpos (* radius xpos)
ypos (* radius ypos)
zpos (* radius zpos)]
(camera xpos ypos zpos 0 0 0 0 -1 0)))
 
(defsketch circles
:title "spinning circles"
:setup setup
:draw draw
:size [800 800]
:renderer :opengl
:target :perm-frame)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.