FORUMS: list search recent posts

Random number from array to target layer

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
David Wiffen
Random number from array to target layer
on Nov 22, 2010 at 4:18:28 pm

Hi Everyone,

Ok hopefully this is simple enough. Here's my expression...

posx = thisComp.layer("Emitter.2").transform.position[0];
posy = thisComp.layer("Emitter.2").transform.position.wiggle(thisComp.layer("WiggleEmitter").effect("Freq")("Slider"),thisComp.layer("WiggleEmitter").effect("Amp")("Slider"))[1];
[posx,posy];


All I want to do is where it references "Emitter.2" I want to have an expression that says randomly select an number from an array of x amount and apply to this reference. So when I duplicate the layer up it will pick a different number each time.

Eg. Emitter.1 / Emitter.2 / Emitter.3 / Emitter.2/ Emitter.1 / Emitter.3 and so on...

Hope that makes sense!



Return to posts index

Dan Ebberts
Re: Random number from array to target layer
on Nov 22, 2010 at 4:59:20 pm

This would be one way to randomize references to the 3 layers:

seedRandom(index,true);
n = Math.floor(random(3)) + 1;
emitterName = "Emitter." + n;
posx = thisComp.layer(emitterName).transform.position[0];


Dan



Return to posts index

David Wiffen
Re: Random number from array to target layer
on Nov 22, 2010 at 5:15:41 pm

Very impressive - Thanks Dan!

One more question...If I have other expressions on the same layer that I want to have the same value as what the random expression chooses...how would I do that?

eg.

This is on position x and y and works great:

seedRandom(index,true);
n = Math.floor(random(3)) + 1;
emitterName = "Emitter0" + n;
posx = thisComp.layer(emitterName).transform.position[0];
posy = thisComp.layer(emitterName).transform.position.wiggle(thisComp.layer("WiggleEmitter").effect("Freq")("Slider"),thisComp.layer("WiggleEmitter").effect("Amp")("Slider"))[1];
[posx, posy] - value + wiggle(thisComp.layer("WiggleEmitter").effect("Freq")("Slider"),thisComp.layer("WiggleEmitter").effect("Amp")("Slider"));


This is on the z and needs to have the same random value as the x and y have for the emitter number:

seedRandom(index,true);
n = Math.floor(random(3)) + 1;
emitterName = "Emitter0" + n;
thisComp.layer(emitterName).transform.position[2];


thanks again Dan - you're talented guy!



Return to posts index


Dan Ebberts
Re: Random number from array to target layer
on Nov 22, 2010 at 8:07:25 pm

You'd have to put the random calculation on a slider control and have both expressions pick it up from there. The expression on the slider would just be:

seedRandom(index,true);
Math.floor(random(3)) + 1;


Dan



Return to posts index

Lloyd Alvarez
Re: Random number from array to target layer
on Nov 22, 2010 at 9:28:43 pm

You could add a slider control and generate the random number there then have X and Z get the number from there.

This is the code you should put on the slider control:
seedRandom(index,true);
Math.floor(random(3)) + 1;


And this would be the updated code for Z:

n=effect("Slider Control")("Slider").value;
emitterName = "Emitter0" + n;
thisComp.layer(emitterName).transform.position[2];


-Lloyd

http://aescripts.com


Return to posts index

David Wiffen
Re: Random number from array to target layer
on Nov 23, 2010 at 9:20:34 am

Brilliant - thanks Both!
Really really appreciate it!



Return to posts index

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