We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › redraw() ing for beginners
Page Index Toggle Pages: 1
redraw() ing for beginners (Read 948 times)
redraw() ing for beginners
Oct 22nd, 2005, 2:45am
 
I can´t get redraw() to work. Why does this code not work

void setup(){
 size(400, 100);
 noLoop();
 forever();
}

void draw(){
 println (i++);
}

void forever(){
boolean neverend = true;  
while (neverend)
   redraw();    
}




And this one does work?:

void setup(){
 size(400, 100);
}

void draw(){
 println (i++);
}


Re: redraw() ing for beginners
Reply #1 - Oct 22nd, 2005, 2:48am
 
I should add that "does not work" means it freezes processing and I have to force quit it. I am on a Mac OS10.3.
Re: redraw() ing for beginners
Reply #2 - Oct 22nd, 2005, 5:17pm
 
redraw is a "request" to redraw.. that function becomes an infinite loop because it never has a chance to exit the function and call draw().
Re: redraw() ing for beginners
Reply #3 - Oct 23rd, 2005, 1:48am
 
well thanks. How would I redraw something from outside the draw() function?
Re: redraw() ing for beginners
Reply #4 - Oct 23rd, 2005, 7:35am
 
redraw() will work fine in functions, you just need to put it somewhere that's not inside of a while() loop that never ends the way you had it in your code. the problem is that your "forever" function never finishes. it's what's known as an "infinite loop", which is what's crashing your machine.

for instance, this would work fine:

void setup() {
 // set things up
 noLoop();
}

void draw() {
 // draw something
}

void mousePressed() {
 redraw();
}

(except with opengl, which currently has a bug with noLoop)
Re: redraw() ing for beginners
Reply #5 - Oct 23rd, 2005, 11:05pm
 
Thanks much for your time and energy, fry. I think I got the point.

Last question: What do I do if I have a neverending loop or a recursive function or anything similar that runs endlessly and want to draw something from inside? Is there a way?

Re: redraw() ing for beginners
Reply #6 - Oct 25th, 2005, 4:33pm
 
Hello Mr. Wong

I think you are misunderstanding something.

In Processing, your entire scene gets drawn to screen at the "end" of the draw() function. Meaning, only after everything has been executed (your for loops, functions, objects) will your stuff be actually "drawn" to screen.

You don't want to actually "manually" draw to screen using a for loop or by using redraw(). The draw() function itself will infinitely loop if untouched, on its own.
Re: redraw() ing for beginners
Reply #7 - Oct 25th, 2005, 10:49pm
 
Hello Mr. mflux,

Thank you very much for the explanation. I now understand that if I need a loop, I best use draw().

Please let me rephrase my original question:

I am working on a webcrawler in processing using a function called
crawl_url (String pagename; int level) that recursively calls itself.

As far as I know I can not achieve this with draw().

Is it possible to directly draw graphical information from inside this recursion in processing and how would I achieve this?


Thanks again for your patience.

Mr.W
Re: redraw() ing for beginners
Reply #8 - Oct 25th, 2005, 11:36pm
 
for that you need to run a separate thread that handles the crawling, and then  use draw to update the screen based on the results.

you should look at the threading tutorial on the java web site for an introduction to that, and try to find an example of writing a crawler in java.. it's easy-ish but there are some basic things that are important to do properly. i think there was an old "javaworld" magazine about it that would get you started.
Re: redraw() ing for beginners
Reply #9 - Oct 26th, 2005, 1:18pm
 
I will try there. Thanks much for helping.
Page Index Toggle Pages: 1