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 › time-programming
Page Index Toggle Pages: 1
time-programming (Read 2654 times)
time-programming
May 26th, 2010, 11:57am
 
Hey poeple,

how is the command if i want to use a countdown (f.e. based on time).

f.e.:

when i press the f.e.:  mouse, the programm should  run after 20 seconds a command (like rect()). Then after 1 minute another command (also rect()).  After 3 minutes another command. And after 1 houer another one.

I know that i can use the time like:
Code:

if (second() < 20){
rect ();
}

or
Code:

if (minute() > 33 && minute() < 35){
rect()
}



But i want to use ist like a counter or countdown, like:
Code:

if (mousePressed()){ // or better: when sketch. is runing
rect();
"after 10 seconds  // sketch is running for 10 seconds
'RUN'
blackground(0)";
}



I hope you  get me :}

greetings.
Re: time-programming
Reply #1 - May 26th, 2010, 1:34pm
 
for example
Re: time-programming
Reply #2 - May 26th, 2010, 1:47pm
 
I guess this is what you're looking for;
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/Timer.html
Re: time-programming
Reply #3 - May 26th, 2010, 1:51pm
 
I don't know how accurate you want it to be timewise, but if you want the program to 'do stuff' at different intervals, perhaps you could use either frameCount or a manual counter. The latter could for example be influenced with mouse or key presses or resetted if needed.

Code:
void setup() {
 size(400,400);
 background(255);
 frameRate(60); // 60 frames per second (default)
}

void draw() {
 // frameCount 600 = 10 seconds
 if (frameCount == 600) {background(200,0,0);}
 // frameCount 1200 = 20 seconds
 if (frameCount == 1200) {background(0,200,0);}
 // frameCount 3600 = 1 minute
 if (frameCount == 3600) {background(0,0,200);}
 println(frameCount);
}
Re: time-programming
Reply #4 - May 26th, 2010, 2:00pm
 
Thanks guys, thats what i was looking for.

I guess i ll have to work a little bit on this new informations.

Thank you very much :]

(Still open for another ideas).
Re: time-programming
Reply #5 - May 26th, 2010, 2:21pm
 
Timer related questions get asked a lot: i.e. search the forum/site.

The usual response involves using millis(); particularly if you need something more accurate than frameCount...
Page Index Toggle Pages: 1