xxxxxxxxxx
50
class Tree {
constructor(start, leafs, branchs) {
this.pos = createVector(start.x, start.y);
this.theta = PI / random(4, 6);
this.len = random(0.15 * windowHeight, 0.1875 * windowHeight);
this.ratio = random(0.6, 0.77);
this.stroke = this.len / random(0.0088 * windowHeight, 0.015 * windowHeight);
this.leafColors = leafs;
this.branchCol = branchs;
}
draw() {
translate(this.pos);
stroke(this.branchCol);
strokeWeight(this.stroke);
let r = random(-0.5, -0.3)
line(0, 0, 0, r * this.len);
translate(0, r * this.len);
this.branch(this.len, this.stroke);
}
branch(len, str) {
let r = random(-(0.00625 * windowHeight), 0.00625 * windowHeight)
strokeWeight(str);
line(0, 0, 0, -len + r);
translate(0, -len + r);
len *= this.ratio;
str *= this.ratio;
if (len < 0.005 * windowWidth) {
noStroke();
fill(this.leafColors[int(random(0, 3))]);
ellipse(0, 0, random(0.0075 * windowHeight, 0.0125 * windowHeight), random(0.0075 * windowHeight, 0.0125 * windowHeight))
return;
}
push();
rotate(this.theta + random(-0.5, 0.5));
this.branch(len, str);
pop();
push();
rotate(-this.theta + random(-0.5, 0.5));
this.branch(len, str);
pop();
}
}