-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbranch.js
52 lines (47 loc) · 1.18 KB
/
branch.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
// Coding Rainbow
// Daniel Shiffman
// http://patreon.com/codingtrain
// Code for: https://youtu.be/kKT0v3qhIQY
class Branch {
constructor(parent, pos, dir) {
this.pos = pos;
this.parent = parent;
this.dir = dir;
this.origDir = this.dir.copy();
this.count = 0;
this.len = 5;
}
reset() {
this.dir = this.origDir.copy();
this.count = 0;
}
next() {
let nextDir = p5.Vector.mult(this.dir, this.len);
let nextPos = p5.Vector.add(this.pos, nextDir);
let nextBranch = new Branch(this, nextPos, this.dir.copy());
return nextBranch;
}
show() {
// if (isDone==true){
// if (this.parent != null) {
// push();
// fill(255);
// ellipse(this.pos.x, this.pos.y,20);
// //line(this.pos.x, this.pos.y, this.parent.pos.x, this.parent.pos.y);
// pop();
// }
// }else{
if (this.parent != null) {
push();
stroke(0);
strokeWeight(15);
line(this.pos.x, this.pos.y, this.parent.pos.x, this.parent.pos.y);
//stroke(255,226,13);
stroke(255);
strokeWeight(12.5);
line(this.pos.x, this.pos.y, this.parent.pos.x, this.parent.pos.y);
pop();
}
// }
}
}