Skip to content

Instantly share code, notes, and snippets.

@CSchoel
Created January 27, 2015 13:28
Show Gist options
  • Save CSchoel/f077136b6aac50fa19c2 to your computer and use it in GitHub Desktop.
Save CSchoel/f077136b6aac50fa19c2 to your computer and use it in GitHub Desktop.
Recursive tree structure with angles depending on mouse position
//Autor: Christopher Schölzel
float angle = 0;
void setup() {
size(400,400);
}
void draw() {
background(255);
translate(width/2.0,height);
drawTree(angle,0.7,100);
}
void drawTree(float rotation, float ratio, float len) {
if (len < 5) return;
println(len);
line(0,0,0,-len); //linie mit länge len gerade nach oben zeichnen
pushMatrix();
translate(0,-len);
rotate(rotation);
//rechte Verzweigung
drawTree(rotation,ratio,len*ratio);
popMatrix();
pushMatrix();
translate(0,-len);
rotate(-rotation);
//linke Verzweigung
drawTree(rotation,ratio,len*ratio);
popMatrix();
}
void mouseMoved() {
angle = map(mouseX,0,width,0,HALF_PI);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment