hi,
i'm relatively new to processing, so this is by far my most ambitious sketch in the environment.
my question goes something like this: is it possible to pass a local variable from the branch-object back to draw()?
i want to put the local variable 'h' in a println() in draw (line 27).
tanks in advance
/claus
Code:
float theta = 12.0;
float minLength = 2.0;
int firstBranch = 250;
PFont font;
void setup() {
size(900, 800);
smooth();
stroke(1, 255, 40);
strokeWeight(0.5);
noLoop();
background(0);
font = loadFont("garamond.vlw");
textFont(font);
}
void draw() {
theta = radians(theta);
translate(width/2, height);
line(0, 0, 0, -firstBranch);
translate(0, -firstBranch);
branch(firstBranch);
resetMatrix();
text("angle each step: " + round(degrees(theta)) + " degrees", width-200, height-100);
//text("branch reduct. / step: " + h, width-200, height-80);
text("minimum branch length: " + minLength, width-200, height-60);
}
void branch(float h) {
h *= 0.66;
if (h > minLength) {
// make branches to the right
pushMatrix();
rotate(theta);
line(0, 0, 0, -h);
translate(0, -h);
branch(h);
popMatrix();
// make branches to the left
pushMatrix();
rotate(-theta);
line(0, 0, 0, -h);
translate(0, -h);
branch(h);
popMatrix();
}
}