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 › controlling the rate of the random object
Page Index Toggle Pages: 1
controlling the rate of the random object (Read 886 times)
controlling the rate of the random object
Aug 14th, 2007, 11:04pm
 
is it possible to change the rate of how often a new number is sent by the random object? i cant use frameRate since it crappity smacks my app as i am dealing with fast moving objects..

Slm
Re: controlling the rate of the random object
Reply #1 - Aug 14th, 2007, 11:22pm
 
random doesn't "send" numbers, it just returns one every time you ask. Without more information about what you're doing, it's impossible to give you any advice.
Re: controlling the rate of the random object
Reply #2 - Aug 15th, 2007, 4:19pm
 
I know.. Smiley

Example.
I want to control how often the color of this box changed.


void setup(){
 
 size(120,120);
 background(0);
}

void hello(){

 fill(int(random(0,255)),int(random(00,255)),int(random(0,255)),100);
 rect(10,10,100,100);

}

void draw(){
 hello();

}
Re: controlling the rate of the random object
Reply #3 - Aug 15th, 2007, 4:54pm
 
There's a couple of ways you can do it:

Code:
//change it every other frame..
if(frameCount%2 == 0)
{
fill(.....);
}
rect(...);


or...

Code:
int last=0;

//...

void hello()
{
//change it every 1/10th of a second.
if(millis()>last+100)
{
last=millis();
fill(...);
}
rect(...);
}
Re: controlling the rate of the random object
Reply #4 - Aug 15th, 2007, 5:02pm
 
you see, thats the problem. i'm sorry i wasn't specific enough.

the problem is that the rect size depends on the input of a microfone. if i use this code, the movement of the rect will not be as smooth as i want it to..
Re: controlling the rate of the random object
Reply #5 - Aug 15th, 2007, 5:37pm
 
the rect will still draw and move as smoothly as before, it'll just only change colour every now and then. you see only the fill command is within the if(...) block, so only that is slowed down, all the rest of the code runs at the same speed as previously.
Re: controlling the rate of the random object
Reply #6 - Aug 16th, 2007, 6:35pm
 
oh.. of course. thank you very much!

Slm
Page Index Toggle Pages: 1