Skip to content

Instantly share code, notes, and snippets.

@davidrusu
Created October 6, 2016 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidrusu/66b39bc10ca5e174fb01f9cb87392606 to your computer and use it in GitHub Desktop.
Save davidrusu/66b39bc10ca5e174fb01f9cb87392606 to your computer and use it in GitHub Desktop.
void setup() {
size(500, 500);
}
void tree(float x, float y, float length, float angle) {
if (length < 2) {
return;
}
float ny = y - length * sin(angle);
float nx = x + length * cos(angle);
stroke(0);
line(x, y, nx, ny);
float dangle = PI/2 * ((float) mouseX / width) * random(0, 1);
float bias = PI/2 * ((float) mouseY / height - 0.5);
float new_l = length * random(0.5, 0.9);
tree(nx, ny, new_l, angle + dangle + bias);
tree(nx, ny, new_l, angle - dangle + bias);
}
void draw() {
background(255);
randomSeed(0);
tree(width / 2, height, height / 5, PI/2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment