Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Chap sketch is now in color.

  • Loading branch information...
commit 87edd81eb98e385a0e8533680180301eac39bbae 1 parent e98e986
Phil Hagelberg authored April 11, 2012

Showing 1 changed file with 13 additions and 10 deletions. Show diff stats Hide diff stats

  1. 23  src/sketchbook/chap.clj
23  src/sketchbook/chap.clj
@@ -7,8 +7,6 @@
7 7
 
8 8
 (def p (atom [0 0]))
9 9
 
10  
-(def c (atom 255))
11  
-
12 10
 (defn within [bound n]
13 11
   (cond (< 0 n bound) n
14 12
         (< n 0) (Math/abs n)
@@ -18,17 +16,22 @@
18 16
   (+ n (- (random (* 2 r)) r)))
19 17
 
20 18
 (defn update [[x y]]
21  
-  [(within (width) (walk x 5))
22  
-   (within (height) (walk y 5))])
  19
+  [(within (width) (walk x 10))
  20
+   (within (height) (walk y 10))])
  21
+
  22
+(defn colors [x y w h]
  23
+  [(* (/ x w) 255) (* (/ y h) 255) 255])
23 24
 
24 25
 (defn draw []
25  
-  (swap! p update)
26  
-  (swap! c #(within 255 (walk % 5)))
27  
-  (fill @c)
28  
-  (stroke (- 255 @c))
29  
-  (apply ellipse (concat @p [15 15])))
  26
+  (let [[x y] (swap! p update)
  27
+        colors (colors x y (width) (height))
  28
+        size (+ 10 (* 20 (/ (- (+ (width) (height)) x y) (+ (width) (height)))))
  29
+        border (+ 20 (* 30 (+ 1 (Math/sin (/ (frame-count) 100)))))]
  30
+    (apply stroke (map (partial + border) colors))
  31
+    (apply fill colors)
  32
+    (apply ellipse [x y size size])))
30 33
 
31 34
 (defsketch chap
32 35
   :setup setup
33 36
   :draw #'draw
34  
-  :size [323 200])
  37
+  :size [646 400])

0 notes on commit 87edd81

Please sign in to comment.
Something went wrong with that request. Please try again.