let number = 25; function setup() { createCanvas(1280, 720); background(0); stroke(121, 84, 56, 150); strokeWeight(1); drawBar(width / 2, height - 10, 100, PI / 2, number); } function drawBar(x0, y0, length, theta, N) { if (N > 0) { let x = x0 + length * cos(theta); let y = y0 - length * sin(theta); line(x0, y0, x, y); if (N < number / 2) { stroke(49, 226, 22, 150 - 150 * (N / number)); if (random(0.0, 1.0) < 0.8) { stroke(49, 226, 22, 20); drawBar(x, y, length * random(0.6, 1.0), theta + random(PI / 8, PI / 7), N - 1); } if (random(0.0, 1.0) < 0.8) { stroke(49, 226, 22, 20); drawBar(x, y, length * random(0.6, 1.0), theta - random(PI / 8, PI / 7), N - 1); } } else { //stroke(121, 84, 56, 150 * (N / number)); if (random(0.0, 1.0) < 0.8) { stroke(121, 84, 56, 150 * (N / number)); drawBar(x, y, length * random(0.6, 1.0), theta + random(PI / 8, PI / 7), N - 1); } if (random(0.0, 1.0) < 0.8) { stroke(121, 84, 56, 150 * (N / number)); drawBar(x, y, length * random(0.6, 1.0), theta - random(PI / 8, PI / 7), N - 1); } } } } function keyPressed() { if (key == 's') { save('fractal_tree_simple.png'); } }