Created
January 27, 2015 13:28
-
-
Save CSchoel/f077136b6aac50fa19c2 to your computer and use it in GitHub Desktop.
Recursive tree structure with angles depending on mouse position
This file contains 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
//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