Skip to content

Recursive arboretum

An experiment in recursion and faking depth through color and position. Click to regenerate.

A forest of trees of blue blossoms and black branches against a pink background

function setup() {
  createCanvas(400, 400);
}


function mousePressed() {
  loop()
}

function draw() {
  background(230, 220, 210);
  fill(230, 220, 210);
  stroke(160, 160, 150)
  tree(150 + random() * 100, 450 + random() * 40, 250, 6);
  stroke(70, 80, 80)
  tree(random() * 400, 400 + random() * 40, 160, 5);
  tree(50 + random() * 300, 400 + random() * 40, 160, 5);
  tree(100 + random() * 200, 400 + random() * 40, 160, 5);
  stroke(3, 20, 10)
  fill(200, 255, 255)
  tree(200, 396, 180, 5);
  noLoop()
}

function tree(x, y, s, w) {
  let r = (random() + random()) / 2
  let r0 = 1 - (random() + random()) / 2
  let r1 = (random() + random()) / 2
  let r2 = (random() + random()) / 2
  strokeWeight(max(w, 1))
  line(x, y,  x - s * r, y - s * r1)
  line(x, y,  x + s * r0, y - s * r2)
  circle(x, y, 3)
  //circle(x, y, 5 + max(w,-2))
  if (s > 10) {
    tree(x - s * r, y - s * r1, s * (1 + random() + random()) / 3, w - 1, r)
    tree(x + s * r0, y - s * r2, s * (1 + random() + random()) / 3, w - 1, r)
  } else {
    circle(x - s * r, y - s * r1, 3)
    circle(x + s * r0, y - s * r1, 3)
  }
}

(Originally seen at https://editor.p5js.org/bojidar-bg/sketches/aybEFv_0l)

Experiments tagged p5 (3/85)

|← Experiments tagged fractal (1/3)

Experiments on this site (3/85)