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 › Newbie: Random function and images
Page Index Toggle Pages: 1
Newbie: Random function and images (Read 460 times)
Newbie: Random function and images
May 8th, 2007, 6:30pm
 
Hi,
This is a total beginners question, I hope somebody can help me out. Using some of the examples from processing and JMyron, I've managed to get an image of my own to track motion from a camera. What I'd like to for the image to change every 30 seconds or so.

I have a large collection of sequentially numbered images (1.png, 2.png etc), and want to randomly switch between them. I'm currently using the image function to draw my PNG files. What's the best way to do this? I think I know how to get processing to select a random file, but it's the changing it every 30 seconds I don't really understand.

Hope somebody can help me out here - thanks a lot!
Re: Newbie: Random function and images
Reply #1 - May 8th, 2007, 7:01pm
 
millis is your friend (milliseconds since the sketch started). do something like:

Code:

int last = 0;
void setup()
{
   last = 0;  
}
void draw()
{
   int now = millis()/1000/30;
   if ( now > last ) {
       // change picture
       println( 30 );
       last = now;
   }
}


F
Re: Newbie: Random function and images
Reply #2 - May 8th, 2007, 9:48pm
 
i just realized that my previous code did not work, soorry. replaced it with something working.

be aware that this is not an exact way of using time as trigger .. i might be delayed a little bit.

F
Page Index Toggle Pages: 1