ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Random placement within a grid

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Agatha Amarelli
Random placement within a grid
on Oct 29, 2019 at 1:06:19 pm

Hi everyone!

I have a 1920x1080 grid with 8 columns and 4 rows, where each spot is 240x270 px. I have several animation comps of the same size, which I want to dispay randomly within the grid. I've almost managed to do it, using the expression below. But I am still struggling to prevent my cops from landing in the middle of the spots, or beyond the comp's boundaries. What am I missing? Thanks in advance!

distanceApartX = thisComp.width/16;
distanceApartY = thisComp.height/8;

minVal = [1,1];
maxVal = [16,8];

holdTime = .5; //time to hold each position (seconds)
seed = Math.floor(time/holdTime);
seedRandom(seed,true);
x = (Math.floor(random(minVal[0], maxVal[0]))*distanceApartX);

y = Math.floor(random(minVal[1], maxVal[1]))*distanceApartY;

[x,y];


Return to posts index

Dan Ebberts
Re: Random placement within a grid
on Oct 29, 2019 at 4:35:12 pm

This should work:

numCols = 8;
numRows = 4;
distanceApartX = thisComp.width/numCols;
distanceApartY = thisComp.height/numRows;
holdTime = .5; //time to hold each position (seconds)
seed = Math.floor(time/holdTime);
seedRandom(seed,true);
x = Math.floor(random(numCols));
y = Math.floor(random(numRows));
[distanceApartX,distanceApartY]/2 + [x*distanceApartX,y*distanceApartY]


Dan



Return to posts index

Agatha Amarelli
Re: Random placement within a grid
on Oct 29, 2019 at 8:28:55 pm

Like a charm! Thank you! I'm gonna sit down and try to figure out why I couldn't figure it out. I almost had it ☺ You're amazing, thanks so much!


Return to posts index

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