Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Creating a random number grid that automatically positions x and position y.

  • Creating a random number grid that automatically positions x and position y.

    Posted by David Santamaria on June 24, 2019 at 7:09 am

    Hi, I am trying to create a random number grid having the x position expressed by index*(pixel value that fills the grid horizontally). Then when the first column fills, the x position returns to 1st column but the y position goes down to a certain amount of pixels. I am able to get it to work for 2 columns and rows with a multi-condition statement, but I know that it could be written as an equation, but not sure how to do it in javascript. There’s always 19 columns before it should repeat so I’m guessing something to do with a variable representing multiples of 19 so that y position would drop down every 20, but at a loss beyond that. Appreciate any help with this. Thanks, David

    x position code//
    if (index<=19) {
    index*192
    } else if (index>19 || index<=38) {
    (index-19)*192
    } else if (index>38 || index<=57) {
    (index-38)*192
    } else if (index>57 || index<=76) {
    (index-57)*192
    } else if (index>76 || index<=95) {
    (index-76)*192
    } else if (index>95 || index<=114) {
    (index-95)*192
    }

    y position code//

    if (index<=19) {
    144
    } else if (index>19 || index<=38) {
    288
    } else if (index>38 || index<=57) {
    432
    } else if (index>57 || index<=76) {
    576
    } else if (index>76 || index<=95) {
    720
    } else if (index>95 || index<=114) {
    864
    }

    random number code (which is working okay to generate a random number between 1 and 9//

    seedRandom(1,true);
    Math.round(random(1,9));

    David Santamaria replied 7 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    June 24, 2019 at 8:50 am

    multiplier = 20;
    columnNumber = 5;
    xpos = (index-1)%columnNumber*multiplier;
    ypos = Math.ceil(index/columnNumber)*multiplier;
    [xpos,ypos]

    If you want different multiplier on columns/rows:

    columnMultiplier = 20;
    rowMultiplier = 25;
    columnNumber = 5;
    xpos = (index-1)%columnNumber*rowMultiplier;
    ypos = Math.ceil(index/columnNumber)*columnMultiplier ;
    [xpos,ypos]

    Andrei
    My Envato portfolio.

  • David Santamaria

    June 24, 2019 at 8:57 pm

    Hi Andrei, A huge thanks to you!

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