ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Implementing random seed but maintaining several objects playing at the same time not just 1

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
wyclef chron
Implementing random seed but maintaining several objects playing at the same time not just 1
on Dec 10, 2012 at 8:25:00 pm

Hey, wanting to use this code to make a composition of a star randomly appear on stage but it only works for 1 at a time. Wondering how I can tweak this to allow for 3, and at varying times not in sync. I could just have 3 different layers and change the holdTime but thought there might be a more logical approach. New to expressions.


holdTime = 2; //time to hold each position (seconds)
minVal = [0.2*thisComp.width, 0.2*thisComp.height];
maxVal = [0.4*thisComp.width, 0.8*thisComp.height];

seed = Math.floor(time/holdTime);
seedRandom(seed,true);
random(minVal,maxVal)


Appreciate any help. Thanks.


Return to posts index

Darby Edelen
Re: Implementing random seed but maintaining several objects playing at the same time not just 1
on Dec 11, 2012 at 4:54:21 am

I believe you can just modify your seed slightly based on the layer index, something like:

seed = Math.floor(time/holdTime) + index;

Darby Edelen


Return to posts index

wyclef chron
Re: Implementing random seed but maintaining several objects playing at the same time not just 1
on Dec 12, 2012 at 10:17:53 pm

hmmm... that didn't seem to work.


Return to posts index


Darby Edelen
Re: Implementing random seed but maintaining several objects playing at the same time not just 1
on Dec 12, 2012 at 11:05:23 pm

[wyclef chron] "hmmm... that didn't seem to work."

Sorry, it seems I didn't quite understand the problem. I'm still not quite sure the behavior you'd like to see but this should be closer:

seedRandom(index, true);
offset = random(0, 1);
holdTime = 2;
minVal = [0.2*thisComp.width, 0.2*thisComp.height];
maxVal = [0.4*thisComp.width, 0.8*thisComp.height];
seed = Math.floor((time + offset)/holdTime);
seedRandom(seed,true);
random(minVal,maxVal)


Each layer will still hold for 2 seconds but the updates of the random values will be offset by up to 1 second from one another.

Alternatively you can just generate a random number for the holdTime per layer:

seedRandom(index, true);
holdTime = random(1, 3);
minVal = [0.2*thisComp.width, 0.2*thisComp.height];
maxVal = [0.4*thisComp.width, 0.8*thisComp.height];
seed = Math.floor(time/holdTime);
seedRandom(seed,true);
random(minVal,maxVal)


Some layers will update more frequently than others with this method.

Darby Edelen


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]