Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random position a square in a range of values for a specific amount of time

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

    Posted by Hassan Ganari on August 17, 2019 at 4:49 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.
    the closest i got was in this link https://forums.adobe.com/thread/2317002

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

    Thank you very very much.

    Dan Ebberts replied 6 years, 11 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    August 17, 2019 at 7:22 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

  • Hassan Ganari

    August 17, 2019 at 9:23 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 ^^

  • Dan Ebberts

    August 17, 2019 at 11:13 pm

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

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy