recursion question (newbie)
in
Programming Questions
•
3 years ago
Hi.
I have a function that I want to be able to call twice, each time from within itself, ie:
void drawArrows(float rotation, float x1, float y1, boolean inc) {
if (depth>maxDepth) {
return;
}
else if(inc){
depth++;
}
translate(x1,y1);
rotate(PI/rotation);
scale(ratio);
float x2 = 0;
float y2 = 0 - lineLength;
stroke(100);
line(0, 0, x2, y2);
drawArrows(rotator,x2,y2,true);
drawArrows(0-rotator,x2,y2,false);
}
In the example above, only the first call to drawArrows is executed (until depth=maxDepth), because it never gets as far as the second call.
Is there a good way to manage multiple levels of recursion whilst always knowing how deep down you are?
thanks!
I have a function that I want to be able to call twice, each time from within itself, ie:
void drawArrows(float rotation, float x1, float y1, boolean inc) {
if (depth>maxDepth) {
return;
}
else if(inc){
depth++;
}
translate(x1,y1);
rotate(PI/rotation);
scale(ratio);
float x2 = 0;
float y2 = 0 - lineLength;
stroke(100);
line(0, 0, x2, y2);
drawArrows(rotator,x2,y2,true);
drawArrows(0-rotator,x2,y2,false);
}
In the example above, only the first call to drawArrows is executed (until depth=maxDepth), because it never gets as far as the second call.
Is there a good way to manage multiple levels of recursion whilst always knowing how deep down you are?
thanks!
1