-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
54 lines (49 loc) · 1.17 KB
/
main.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
50
51
52
53
54
var slider_1, slider_2, slider_3, slider_4, slider_5;
var mul;
var maxn;
var angle_1, angle_2;
var cb, cs;
var button;
function setup() {
createCanvas(800, 600);
createP('');
slider_1 = createSlider(-PI, PI, PI / 4, 0.01);
slider_2 = createSlider(-PI, PI, PI / 4, 0.01);
slider_3 = createSlider(0, 13, 5, 1);
slider_4 = createSlider(0, 0.9, 0.67, 0.01);
slider_5 = createSlider(100, 200, 150, 5);
createP('');
button = createButton('GET RANDOM COLOR');
button.mousePressed(randomColor);
randomColor();
}
function draw() {
background(cb);
stroke(cs);
translate(width/2, height);
var len = slider_5.value();
maxn = slider_3.value();
mul = slider_4.value();
angle_1 = slider_1.value();
angle_2 = -slider_2.value();
branch(len, 0);
}
function branch(len, n) {
line(0, 0, 0, -len);
translate(0, -len);
var l = len * mul;
if (n < maxn) {
push();
rotate(angle_1);
branch(l, n + 1);
pop();
push();
rotate(angle_2);
branch(l, n + 1);
pop();
}
}
function randomColor() {
cb = color(random(100));
cs = color(random(100, 256), random(100, 256), random(100, 256));
}