Skip to content

Instantly share code, notes, and snippets.

@manoloide
Created December 1, 2018 03:21
Show Gist options
  • Save manoloide/ed8dae33f5772775b1039ca4e7404479 to your computer and use it in GitHub Desktop.
Save manoloide/ed8dae33f5772775b1039ca4e7404479 to your computer and use it in GitHub Desktop.
int totalIte = 15;
void setup() {
size(600, 600);
generate();
}
void draw() {
}
void keyPressed() {
generate();
}
void generate() {
background(255);
stroke(0, 240);
arbol(width*0.5, height*0.8, width*0.5);
}
void arbol(float x, float y, float s) {
float a = PI*1.5;
s = s/5;
rama(x, y, a, s, totalIte);
}
void rama(float x, float y, float a, float s, int ite) {
float ax = x;
float ay = y;
float str = s*0.01;
x += cos(a)*s;
y += sin(a)*s;
strokeWeight(8*str);
line(ax, ay, x, y);
s *= random(random(0.6, 0.8), 0.95);
ite--;
if (ite > 0) {
if (random(1) < 0.8) rama(x, y, a-random(0.2, 0.4), s, ite);
if (random(1) < 0.8) rama(x, y, a+random(0.2, 0.4), s, ite);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment