xxxxxxxxxx
37
function setup() {
createCanvas(windowWidth, windowHeight);
angleMode(DEGREES);
}
function draw() {
background(255,255,255);
push();
translate(width/2,height/2);
drawTree(0,0,-90,50,5,10);
pop();
}
function drawTree(x1,y1,direction,length,depth,angle) {
if (depth !== 0){
let x2 = x1 + length * cos(direction);
let y2 = y1 + length * sin(direction);
stroke(0,0,0)
strokeWeight(0.5*depth);
line(x1,y1,x2,y2);
drawTree(x2,y2,direction-angle,length,depth-1,angle);
drawTree(x2,y2,direction+angle,length,depth-1,angle);
}
}