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 › Periods of time or intervals in milliseconds
Page Index Toggle Pages: 1
Periods of time or intervals in milliseconds (Read 1011 times)
Periods of time or intervals in milliseconds
Jan 2nd, 2009, 10:39pm
 
Hi,

I am trying to add objects every half a second or so, I manage to get them every 2 seconds but I want it quicker and more adjustable, here is the sample code

// INI CODE SAMPLE

 int so = 0;
 int interval = 2;

in side the draw()

 int s = second() % interval;
 if (s != so) {
   so = s;
   if (s == interval - 1) {
     if (count <  numOrbs) {
       addOrb();
     }
   }
 }

// END CODE SAMPLE

I was trying to use millis() but I havent figure it out yet.
I try millis() % 200 but I never gets a value I can compare to, maybe I need to rest a bit more.

Thanks!
rS
Re: Periods of time or intervals in milliseconds
Reply #1 - Jan 3rd, 2009, 1:04am
 
millis() Doesn't increment smoothly, it goes up in chunks, so unless you're really lucky, it's rarely an exact multiple of 200.

So on time round it could be 194, next time 212 and so your test will fail.

You have to see if "at least" 200 milliseconds have elapsed since last time

e.g.

Code:
int lastMillis=0;

//...

void draw()
{
if(mills()>lastMillis+200)//been at least 200 millis
{
lastMillis=millis(); //wpdate the last time we did anything
//do stuff...
}
}
Re: Periods of time or intervals in milliseconds
Reply #2 - Jan 3rd, 2009, 1:27am
 
Hi JohnG, it WORKS! is just perfect, here is an sample of where I am going with this:

http://homepage.ntlworld.com/ricardo.sanchez/processing/glowingorbs_v2/

What I want to do with this is some sort of birth, survival, death code where the big orbs absorb the small ones, nothing new I know is just to practice my kung fu!

One question I am using noise for the movement and the range is from 0 to width and 0 to height but for some reason they dont go to far from the center, any ideas will be much appreciated.

Cheers
rS
Re: Periods of time or intervals in milliseconds
Reply #3 - Feb 10th, 2009, 7:19pm
 
my first post, and i just want to digress for a second. i am not exactly well versed in processing (i = noob), but i'm experienced in other programs like max/msp/jitter... so hopefully my reply will be somewhat relevant!

with regard to using noise for movement, and probs with getting it to go further from center of canvas... is part of the problem in the orb class, the line which makes imageMode(CENTER)?

and in the var initialisation for the orb class:
float xnoise = random(0, width);
float ynoise = random(0, height);

if it's moving from center, then variables from 0 to width will go from middle of screen to left hand edge...

i guess it should be something like:
float xnoise = random((width/2) - width, width);

brackets might not be right, dont have processing nearby to test...

cheers,
j

ps. nice bit of coding there, quite fun to study and learn!
Page Index Toggle Pages: 1