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.
Page Index Toggle Pages: 1
millis() (Read 1601 times)
millis()
Jan 21st, 2006, 11:59pm
 
Hi,

I know that millis() is keeping track of how long processing has been running. How do I use millis() to trigger an event every x milliseconds? e.g. I want the random(10, 100) to generate the radius of a circle every x milliseconds.

-and can I reset millis(), so that it counts from 0 again while the program is running?
Re: millis()
Reply #1 - Jan 22nd, 2006, 2:11am
 
try something like this:

Code:
void 

float last,rad,interval;

void setup() {
size(300,300);
last=millis();
interval=300; // 300 msecs
rad=random(10, 100);
}

void loop() {
if(millis()-last>interval) {
rad=random(10, 100);
last=millis();
}

ellipse(width/2,height/2, rad,rad);
}


you can't guarantee that it will occur exactly on the millisecond, but this way you check if more time than x msecs has passed. if so, then you carry out the action and reset the reference time.
Page Index Toggle Pages: 1