-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
49 lines (41 loc) · 1014 Bytes
/
sketch.js
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
var tree = [];
var leaves = [];
var count = 0;
function setup() {
createCanvas(700, 700);
var a = createVector(width / 2, height-50);
var b = createVector(width / 2, height - 200);
var root = new Branch(a, b);
tree[0] = root;
}
function mousePressed() {
for (var i = tree.length - 1; i >= 0; i--) {
if (!tree[i].finished) {
tree.push(tree[i].branchA());
tree.push(tree[i].branchB());
}
tree[i].finished = true;
}
count++;
if (count === 6) {
for (var i = 0; i < tree.length; i++) {
if (!tree[i].finished) {
var leaf = tree[i].end.copy();
leaves.push(leaf);
}
}
}
}
function draw() {
background(0);
for (var i = 0; i < tree.length; i++) {
tree[i].show();
//tree[i].jitter();
}
for (var i = 0; i < leaves.length; i++) {
fill(random(255),random(255),random(255));
noStroke();
circle(leaves[i].x, leaves[i].y, 8, 8);
leaves[i].y += random(0, 2);
}
}