gravix wrote on May 11th, 2010, 2:09pm:So a recursive step-printing, like my proposed "for" printing, would be impossible unless each step was "saved" within a class, correct
Technically true, but the sketch itself is a class, and you can just define a variable to store your current position, like so:
Code:
void setup()
{
size(500,500);
noStroke();
colorMode(RGB, 255, 255, 255, 100);
frameRate(1);
}
int i = 0;
void draw()
{
i++;
if (i >=20) i = 0;
rect(20*i,20,20,20*i);
}
Quote:For example, if I wanted to do a tree traversal and print step-by-step to the screen, I would have to somehow save my location and locate it again after I print to the screen. Is this correct? How would I go about doing something like that?
If by "print to the screen" you mean "display it nicely in the sketch window" then yes. You'd need to have a way to advance your tree-traversal one step at a time and store the current state in some way after each step.
(If you're simply trying to get the data to your eyes in some kind of usable format for debugging purposes, then I'd recommend using println().)