Created
October 6, 2016 02:45
-
-
Save davidrusu/66b39bc10ca5e174fb01f9cb87392606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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