Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Dancer with colors and motion paths
(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.