shunic
This commit is contained in:
parent
fa330a3e2d
commit
ac1bb39302
|
@ -10,43 +10,62 @@
|
|||
; setup function returns initial state. It contains
|
||||
; circle color and position.
|
||||
{:color 0
|
||||
:angle 0})
|
||||
:angle 0
|
||||
:counter 0
|
||||
:range 50})
|
||||
|
||||
(defn update-state [state]
|
||||
; Update sketch state by changing circle color and position.
|
||||
{:color (mod (+ (:color state) 0.7) 255)
|
||||
:angle (+ (:angle state) 0.1)})
|
||||
:angle (+ (:angle state) 0.1)
|
||||
:counter (+ (:counter state) 1)
|
||||
:range (if (= 4 (mod (:counter state) 20)) (q/random 20 50) (:range state))})
|
||||
|
||||
(defn tri
|
||||
[x y delta]
|
||||
(q/triangle x y x (- y delta) (- x delta) y)
|
||||
(q/triangle x y x (+ y delta) (- x delta) y)
|
||||
(q/triangle x y x (- y delta) (- x delta) y)
|
||||
(q/triangle x y x (+ y delta) (+ x delta) y))
|
||||
[x y delta r]
|
||||
(q/triangle x y (* r x) (- y delta) (- x delta) y)
|
||||
(q/triangle x (* r y) x (+ y delta) (- x delta) y)
|
||||
#_(q/triangle x y x (- y delta) (- x delta) y)
|
||||
#_(q/triangle x y x (+ y delta) (+ x delta) y))
|
||||
|
||||
(defn draw-state [state]
|
||||
; Clear the sketch by filling it with light-grey color.
|
||||
(q/background 0)
|
||||
; Set circle color.
|
||||
(q/fill (:color state) 255 255)
|
||||
(q/stroke 55 100)
|
||||
|
||||
(let [angle (:angle state)
|
||||
r (:range state)
|
||||
size 50
|
||||
x1 (* size (q/cos angle))
|
||||
y1 -50
|
||||
x1 (* 0.7 size (q/cos angle))
|
||||
y1 (* 0.3 size (q/sin angle))
|
||||
x2 (+ x1 size)
|
||||
y2 (+ y1 size)
|
||||
delta (/ size 2)]
|
||||
(q/with-translation [(/ (q/width) 2)
|
||||
(/ (q/height) 2)]
|
||||
#_(q/rect x1 y1 size size)
|
||||
(tri x1 y1 (* delta (q/cos angle)))
|
||||
(tri x2 y1 delta)
|
||||
(tri x1 y2 delta)
|
||||
(tri x2 y2 (* delta (q/sin angle)))
|
||||
)
|
||||
(doseq [i (range -300 300 r)]
|
||||
(q/push-matrix)
|
||||
(q/fill (* r (:color state)) (* 0.5 (:color state)) (+ 100 (:color state)))
|
||||
(q/rotate (q/radians (* delta (q/cos (+ i angle)))))
|
||||
(tri (+ i x1) y1 (* delta (q/cos angle)) r)
|
||||
(tri x1 (+ y1 i) (* delta (q/sin angle)) r)
|
||||
(q/pop-matrix))
|
||||
(doseq [i (range -400 400 (* 0.6 r))]
|
||||
(q/push-matrix)
|
||||
(q/fill (* 0.6 r (:color state)) (* 0.5 (:color state)) (+ 100 (:color state)))
|
||||
(q/rotate (q/radians (* delta (q/sin (+ i angle)))))
|
||||
(tri (+ i x2) y2 (* delta (q/cos angle)) r)
|
||||
(tri x2 (+ y2 i) (* delta (q/sin angle)) r)
|
||||
(q/pop-matrix))
|
||||
#_(q/push-matrix)
|
||||
#_(q/rotate (q/radians (* delta (q/sin angle))))
|
||||
#_(tri x2 y1 delta)
|
||||
#_(tri x1 y2 delta)
|
||||
#_(q/pop-matrix)
|
||||
#_(tri x2 y2 (* delta (q/sin angle))))
|
||||
|
||||
; Calculate x and y coordinates of the circle.
|
||||
; Calculate x and y coordinates of the circle.
|
||||
#_(let [angle (:angle state)
|
||||
x (* 150 (q/cos angle))
|
||||
y (* 150 (q/sin angle))]
|
||||
|
@ -56,7 +75,7 @@
|
|||
|
||||
(q/defsketch shunic
|
||||
:title "You spin my circle right round"
|
||||
:size [500 500]
|
||||
:size [800 800]
|
||||
; setup function called only once, during sketch initialization.
|
||||
:setup setup
|
||||
; update-state is called on each iteration before draw-state.
|
||||
|
|
Loading…
Reference in a new issue