level 2
const trees = []
// Try changing these constants
Object.defineProperty(Branch, 'HEIGHT', {value: 200})
Object.defineProperty(Branch, 'B_WIDTH', {value: 4, writable: true})
Object.defineProperty(Branch, 'L_WIDTH', {value: 36, writable: true})
Object.defineProperty(Branch, 'SPEED', {value: 0.02, writable: true})
Object.defineProperty(Branch, 'VAR_ANGLE', {value: 0.2, writable: true})
Object.defineProperty(Branch, 'VAR_SCALE', {value: 0.25, writable: true})
Object.defineProperty(Branch, 'C_BRANCH', {value: [255, 255, 255], writable: true})
Object.defineProperty(Branch, 'C_LEAF', {value: [255, 255, 255], writable: true})
function setup() {
createCanvas(windowWidth, windowHeight);
background(179, 214, 110,150)
trees.push(new Branch(width/3, height - 50))
}
function draw() {
for (var i=0; i<trees.length; trees[i++].draw());
}
function mouseClicked() {
trees.push(new Branch(mouseX, mouseY, p5.Vector.fromAngle(PI/2 + random(-1,1) * 0.25), random(0.5) + 0.6))
}
function Branch(x, y, v, scale=1) {
this.x = x
this.y = y
this.v = v || p5.Vector.fromAngle(PI/2+random(-Branch.VAR_ANGLE, Branch.VAR_ANGLE))
this.v.setMag(scale * Branch.HEIGHT)
this.scale = scale
this.cLeft = null
this.cRight = null
this.size = 0
this.growing = true
}