-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch0014.clj
53 lines (45 loc) · 1.28 KB
/
sketch0014.clj
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
(ns quil-sketches.sketch0014
(:use [quil.core]
[quil-sketches.core]))
;; Trying something a little different with colour...
(def start-color)
(def current-color)
(def target-color)
(defn setup []
(smooth)
(frame-rate 30)
(stroke-weight 0)
(dosync
(ref-set target-color (colour-coll))
(ref-set start-color [0.0 0.0 0.0])
(ref-set current-color [0.0 0.0 0.0])))
(defn round-colour-coll [coll]
(map #(java.lang.Math/round %) coll))
(defn target-reached? []
(round-colour-coll @current-color))
(defn next-color []
(when (target-reached?)
(dosync
(ref-set target-color (colour-coll))
(ref-set start-color @current-color)))
(let [jump-percent 10
delta (map #(/ (- % %2) jump-percent) @target-color @start-color)]
(dosync
(ref-set current-color (map + @current-color delta)))
@current-color))
(defn draw []
(let [x (random (width))
y (random (height))
mid-x (/ (width) 2)
mid-y (/ (height) 2)
per-x (percent-from-location mid-x x)
per-y (percent-from-location mid-y y)
combined (/ (+ per-x per-y) 2)
colour (next-color)]
(apply fill colour)
(ellipse x y 50 50)))
(start-sketch
{:name "Oh so many colourful ellipses"
:setup setup
:draw draw
:filename "sketch0014.png"})