Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: ForumAE BasicsAE ExpressionsTutorialsArticlesPodcastsMotion GraphicsTrainingCinema 4D

re: seedRandom(index,true)

Cow Forums : Adobe After Effects Expressions
cow
re: seedRandom(index,true)
by David Rodriguez on May 14, 2008 at 8:30:19 pm

I have used seedRandom(index,true); twice in this expression.
The first works exactly as I would expect it to.
The second seedRandom(index,true); applied to elasticity achieves undesirable results.
This bounce expression is applied to hundreds of ball graphics, instead of randomizing the elasticity across all of the balls it raises the elasticity from .89 to 1 from the left of the screen to the right.

Screen Shot
http://img517.imageshack.us/img517/1050/notrandomsp8.jpg


Vy0 =200; //initial y velocity (pixels/second)
seedRandom(index,true);
Vx0 =random(-400,400); // initial x velocity (pixels/second)
g = 2500; // gravity (pixels/second/second)
floor = 1050;
seedRandom(index,true);
e = random(.89,1); //elasticity

b = floor - position[1];
h = b + Vy0*Vy0/(2*g);
T = Vy0/g + Math.sqrt(2*h/g);

if (time < T){
y = Vy0*time - g*time*time/2 + b;
}else{
Vy = -(Vy0 - g*T);
Vy *= e;
t = time - T;
y = Vy*t - g*t*t/2;
}
[position[0] + Vx0*time, floor - y]

What have I done now? Any help is very much appreciated!
David

Respond to this post     Return to posts index

cow
Re: re: seedRandom(index,true)
by Dan Ebberts on May 14, 2008 at 8:40:18 pm

When you reset the seed to a previous value (the layer's index in this case) the random sequence you get when call random() starts over. So in your case,

random(-400,400);

and

random(.89,1);

actually generate the same random number, scaled by the parameters inside the parens. So that means that elasticity will be proportional to the x velocity, which will give you exactly the results you are seeing.

What were you trying to accomplish be resetting the seed?

Dan



Respond to this post     Return to posts index

cow
Re: re: seedRandom(index,true)
by David Rodriguez on May 14, 2008 at 9:02:21 pm

I would like some of the balls to bounce higher than others.
I thought that using Random would randomly choose an elasticity between .89 and 1

-David


Respond to this post     Return to posts index


cow
Re: re: seedRandom(index,true)
by Dan Ebberts on May 14, 2008 at 9:13:41 pm

It will, but you don't need (or want) to reset the seed first. You should only need to use seedRandom() once in an expression unless you're doing something tricky and need to regenerate a random number from the past.

Dan



Respond to this post     Return to posts index

cow
Re: re: seedRandom(index,true)
by David Rodriguez on May 14, 2008 at 9:23:56 pm

Brilliant! I actually understand!

Is this expression easily changed from one bounce to two?
If not then I can be happy with what you helped me achieve, but two bounces would be nice.

Con Muchas Gracias,
David

-David


Respond to this post     Return to posts index

<< PREVIOUS THREAD   •   VIEW ALL THREADS   •   PRINT   •   NEXT THREAD >>


FORUMSTUTORIALSMAGAZINEDVDsBOOKSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]