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 › Stopping the draw loop
Page Index Toggle Pages: 1
Stopping the draw loop (Read 2001 times)
Stopping the draw loop
May 9th, 2005, 10:44pm
 
How can one stop the execution of the draw loop?

Something that would essentially stop the program until the window is closed.

Thanks,
jared

Re: Stopping the draw loop
Reply #1 - May 10th, 2005, 12:31am
 
our new friend noLoop():
http://processing.org/reference/noLoop_.html
Re: Stopping the draw loop
Reply #2 - May 10th, 2005, 12:32am
 
you could have a counter variable that is incremented every frame, then just don't do anything if the variable is higher than a certain number, or have a boolean variable and tell the program not to do anything if the variable is true.

hth

EDIT: dang fry posted while i was typing.
fry: can that function be called during loop, while the program is running? and is there any way to restart the loop after calling that function?
Re: Stopping the draw loop
Reply #3 - May 10th, 2005, 1:31am
 
loop() and noLoop() can be called inside draw, but redraw() (its cousin) cannot. i'll ask casey to add these notes to the ref.

http://processing.org/reference/redraw_.html
Re: Stopping the draw loop
Reply #4 - May 10th, 2005, 2:27am
 
ok, i just read through the reference for those functions, and there was something i didn't get the reason for having the redraw() functions, couldn't you just call draw() again? or does it do something else im missing?
Re: Stopping the draw loop
Reply #5 - May 10th, 2005, 3:03am
 
yeah, you should never ever call draw(), it won't work and will likely cause badness. maybe we should add that to the docs as well.
Re: Stopping the draw loop
Reply #6 - May 10th, 2005, 3:30am
 
oh, ok.

is it also a bad idea to call setup()? or the mouse functions?
Re: Stopping the draw loop
Reply #7 - May 10th, 2005, 3:58am
 
yes, definitely a bad idea to call setup() yourself.
Re: Stopping the draw loop
Reply #8 - May 21st, 2005, 2:22am
 
In the Alpha version there was an option for pauzing the loop. Have not seen it in the documentation for the Beta version though. Guessed it is gone?

Maybe this was ment? With this option you could have set to pauze the loop for a certain amount of time measured in milliseconds. Can't recall the name of the function though.
Re: Stopping the draw loop
Reply #9 - May 21st, 2005, 2:54am
 
yup, it hasn't changed in beta, it's called delay:
http://processing.org/reference/delay_.html
Re: Stopping the draw loop
Reply #10 - May 21st, 2005, 4:08am
 
Ben:
Really? I call setup() all the time myself, as an easy way to reset the program. What's so bad about it?

Btw you can also pause the draw loop in several ways:

Code:

void draw()
{
//dosomething
while(!keyPressed);
}


This will only allow the software to run while a key is held, essentially pausing until you're happy with it.
Re: Stopping the draw loop
Reply #11 - May 21st, 2005, 5:52am
 
aww, c'mon. would i lie to you? Wink

setup() and draw() are both special functions that are reserved by processing, and there's black magic that has to happen behind the scenes to make them work properly across all the renderers.

so for instance, it might work fine with P3D, but break in opengl, in fact you may even be able to get a good blue screen out of it if you call setup() or draw() yourself in gl mode.

pausing draw() that way may cause problems too. for instance, we can only "ask" gl to render, so if you don't give the thread back to the operating system, there might be problems. similar with JAVA2D. but of course, you're welcome to do what you want so long as you don't complain when it breaks.

i guess we should add a note to the reference so it's explicit.
Re: Stopping the draw loop
Reply #12 - May 21st, 2005, 11:02pm
 
I see it. Yeah. Pausing the loop that way isn't exactly happy. Ouch!

I guess another way is to surround whatever you want to do in the loop with a boolean, and only toggle that on when you want.

Or, write a function that contains everything you want in the draw loop, and only run this function from draw when a boolean is toggled. Same thing, but looks cleaner.

Ah Ben. You're teh true black mage. Maybe processing loves me or something, I've never blue-screened from setup(). Although since then I've learned to write a reset() that restores my software's initial conditions, and is run by setup() the first time, as well as any other time I want to rewind the software.
Re: Stopping the draw loop
Reply #13 - Mar 6th, 2008, 11:02pm
 
I'm sorry to dig this OLD topic, but I have just one question related to everything that was said here.
In the SteupDraw example, I've been trying(just for "fun") to make the draw() function stop after 2 loops. I've tried the whole "counter thing"...but with no luck. I've also tried using noLoop(9 and still no luck.
I was wondering if anyone could show me the altered example code so I can see what I'm doing wrong. Thanks. Smiley
Page Index Toggle Pages: 1