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 › timer in processing
Page Index Toggle Pages: 1
timer in processing? (Read 703 times)
timer in processing?
Jul 17th, 2007, 9:55am
 
hello. is there any possibility to write a timer program in processing?
so that after 30 seconds or 1 minute something will change? e.g. pixel color?

i was looking to minute() and hour()

minutes = minute();
(if (minutes > 30) { colorthepixels(); } //when starting with minutes = 0
it recognizes the seconds for the first time but then it seems to be that it never asks again because when time is changing ---nothing in the program changes. so it doesn't work.

and also delay() does not really fit because it seems to stop the program
it isn't leaving the current state activated to chance after some minutes into another state.

help help
silberhoehe
Re: timer in processing?
Reply #1 - Jul 17th, 2007, 10:37am
 
i think you are just going about it the wrong way. your code will trigger every frame once minute() is larger than 30. is that what you wanted?
... and you really have to wait a lot of time to see the effect.

here's an example of a really simple timer:
Code:

int lastMinute = -1;
int lastSecond = -1;
void draw(){
if ( second() != lastSecond )
{
println( "Every second: "+second() );
lastSecond = second();
}
if ( minute() != lastMinute )
{
println( "Every minute: "+minute() );
lastMinute = minute();
}
if ( frameCount % 50 == 0 )
{
println( "Every 50th frame: "+frameCount );
}
}


F
Re: timer in processing?
Reply #2 - Jul 17th, 2007, 10:42am
 
float currTime = 0;
float activateTime = 0;


setup()
{
 // get time in milliseconds
 currTime = activateTime = millis();
}


draw()
{
 activateTime = millis() - currTime;
 // count 30 seconds
 if( activateTime > 30*1000 )
 {
    doSomething();

    // update currTime (used to reset our counter)
    currTime = millis();
 }
}

that will do..
Re: timer in processing?
Reply #3 - Jul 17th, 2007, 12:00pm
 
thank you very much. its working fine!
Page Index Toggle Pages: 1