Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions random move in a grid

  • random move in a grid

    Posted by Max Arch on October 4, 2015 at 4:12 am

    i have a square shape 40 by 40.
    i want it randomly appear inside my grid, my composition is 1080px by 200px.
    the grid is a by multiple of 40.

    the random function will generate multiple of 40.

    at the moment it appearing with no order.

    holdTime = .3; //time to hold each position (seconds)
    minVal = [0 , 0];
    maxVal = [1080, 200];
    seed = Math.floor(time/holdTime);
    seedRandom(seed,true);
    random(minVal,maxVal);

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

    October 4, 2015 at 6:06 am

    This should work:

    holdTime = .3; //time to hold each position (seconds)
    numCols = 27;
    numRows = 5;
    seed = Math.floor(time/holdTime);
    seedRandom(seed,true);
    col = Math.floor(random(numCols));
    row = Math.floor(random(numRows));
    [col*40+20,row*40+20]

    Dan

  • Max Arch

    October 4, 2015 at 7:36 pm

    i want to be able to customize it for other size
    1-
    example change the code for comp size of 40×40
    and a grid of 10 pixel
    2-
    be able to control the section of the random exaple bettween the col 10 and 15
    it not working
    what did i do wrong

    v = 40; //grid size
    a = 2; //mincol 0
    b = 3; //maxcol 27
    c = 2; //minrow 0
    d = 3; //maxrow 5
    num = random ( 0.1, 0.5); //speed

    holdTime = num; //time to hold each position (seconds)
    seed = Math.floor(time/holdTime);
    seedRandom(seed,true);
    col = Math.floor(random(a,b));
    row = Math.floor(random(c,d));
    [col*v+(v/2),row*v+(v/2)]

  • Dan Ebberts

    October 4, 2015 at 8:28 pm

    Like this, I think:

    v = 40; //grid size
    a = 2; //mincol 0
    b = 3; //maxcol 27
    c = 2; //minrow 0
    d = 3; //maxrow 5
    seedRandom(index,true);
    holdTime = random ( 0.1, 0.5); //speed
    seed = Math.floor(time/holdTime);
    seedRandom(seed,true);
    col = Math.floor(random(a,b+1));
    row = Math.floor(random(c,d+1));
    [col*v+(v/2),row*v+(v/2)]

    Dan

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