ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Random position a square in a range of values for a specific amount of time

FAQ   •   VIEW ALL
 Random position a square in a range of values for a specific amount of time on Aug 17, 2019 at 4:49:41 pm

Hi guys,

I have 1000x1000px comp with 10sec duration, and a 200x200px square layer.
I want the square to show up in EVERY 2 seconds (fade in then out) but every time in a different position, i need that position to be picked random from a range of values.

range = ([0,0],[0,200],[200,0],[0,400],[400,0],[0,600])

I am scratching my head for hours in vain.

This needs to be an expression, not a script please.

Thank you very very much.

 Re: Random position a square in a range of values for a specific amount of timeon Aug 17, 2019 at 7:22:37 pm

try these:

``` // opacity fadeTime = .5; period = 2; t = time%period; if (t < period/2) ease(t,0,fadeTime,0,value) else ease(t,period-fadeTime,period,value,0) //position period = 2; seed = Math.floor(time/period); positions = [[0,0],[0,200],[200,0],[0,400],[400,0],[0,600]]; seedRandom(seed,true); i = Math.floor(random(positions.length)); positions[i]; ```

Dan

 Re: Random position a square in a range of values for a specific amount of timeon Aug 17, 2019 at 9:23:58 pm

Thank you so much Dan,

that worked !

Now I got that problem when I hit play, the same pattern of position is repeated, so i tried to put a slider control and inject it in the seedRandom but i clearly miss the syntax and the algorythm !

Thank you again for your help, it's sooooOO cool ^^

 Re: Random position a square in a range of values for a specific amount of timeon Aug 17, 2019 at 11:13:23 pm

I'm not sure I understand what issue is. You shouldn't get a repeating pattern.

Dan