/
30_random_clicked_circles.clj
63 lines (52 loc) · 1.25 KB
/
30_random_clicked_circles.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
54
55
56
57
58
59
60
61
62
63
(ns quil-sketches.gen-art.30-random-clicked-circles
(:require [quil.core :as q]))
;; Example 30 - Random Clicked Circles
;; Taken from Listing 6.1, p113
;; int _num = 10;
;; void setup() {
;; size(500, 300);
;; background(255);
;; smooth();
;; strokeWeight(1);
;; fill(150, 50);
;; drawCircles();
;; }
;; void draw() {
;; }
;; void mouseReleased() {
;; drawCircles();
;; }
;; void drawCircles() {
;; for(int i = 0; i < _num; i++) {
;; float x = random(width);
;; float y = random(height);
;; float radius = random(100) + 10;
;; noStroke();
;; ellipse(x, y, radius * 2, radius * 2);
;; stroke(0, 150);
;; ellipse(x, y, 10, 10);
;; }
;; }
(def num-circles 10)
(defn draw-circles []
(dorun
(for [_ (range 0 num-circles)]
(let [x (q/random (q/width))
y (q/random (q/height))
radius (+ (q/random 100) 10)]
(q/no-stroke)
(q/ellipse x y (* 2 radius) (* 2 radius))
(q/stroke 0 150)
(q/ellipse x y 10 10)))))
(defn setup []
(q/background 255)
(q/smooth)
(q/stroke-weight 1)
(q/fill 150 50)
(draw-circles))
(q/defsketch gen-art-30
:title "Random Clicked Circles"
:setup setup
:mouse-released draw-circles
:size [500 300])
(defn -main [& args])