# Fractal Trees
const WIDTH = Math.min(window.innerWidth, window.innerHeight, 480);
let angle = 0;
let slider;
function setup() {
createCanvas(WIDTH, WIDTH);
slider = createSlider(0, TWO_PI, PI / 4, 0.01);
slider.elt.classList.add('slider')
}
function draw() {
background(0);
angle = slider.value();
stroke(255);
strokeWeight(2);
translate(width * 0.5, height);
branch(100);
}
function branch(len) {
line(0, 0, 0, -len);
translate(0, -len);
if (len > 4) {
push();
rotate(angle);
branch(len * 0.67);
pop();
push();
rotate(-angle);
branch(len * 0.67);
pop();
}
}