xxxxxxxxxx
34
function Branch(begin, end) {
this.begin = begin;
this.end = end;
this.finished = false;
this.jitter = function() {
this.end.x += random(-1, 1);
this.end.y += random(-1, 1);
}
this.show = function() {
stroke(255);
line(this.begin.x, this.begin.y, this.end.x, this.end.y);
}
this.branchA = function() {
let dir = p5.Vector.sub(this.end, this.begin);
let angle = random(0, PI/3);
dir.rotate(angle);
dir.mult(0.67);
let newEnd = p5.Vector.add(this.end, dir);
let a = new Branch(this.end, newEnd);
return a;
}
this.branchB = function() {
let dir = p5.Vector.sub(this.end, this.begin);
let angle = random(-PI/3, 0);
dir.rotate(angle);
dir.mult(0.67);
let newEnd = p5.Vector.add(this.end, dir);
let b = new Branch(this.end, newEnd);
return b;
}
}