ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Random positions

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Sanniti Towiwat
Random positions
on Mar 16, 2018 at 9:58:00 am

Hello everyone

This is my first question here.

I have a composition with many layers about 50+ layers each one is animated

I want them to pop out in random position so I used this expression for each one;

seedRandom(index, true);
x = random(0, thisComp.width);
y = random(0, thisComp.height);
[x, y]

but some of layers are overlap and out of comp space.

I want them being separate and not overlap each other and still in comp space.

This is my current result here:

Thank you.

Return to posts index

Kevin Camp
Re: Random positions
on Mar 19, 2018 at 5:29:55 pm

you need the expression to account for layer height and width when calculating the boundaries for the random position area.

if the anchor points are in the centers of each layer, this should deep them within the boundaries of the comp:
seedRandom( index, true ) ;
xSize = width * scale[0] / 100 ;
ySize = height * scale[1] / 100 ;
x = random( xSize / 2, thisComp.width - xSize / 2 ) ;
y = random( ySize / 2, thisComp.height - ySize / 2 ) ;
[x, y]

I don't know of a good way to prevent overlapping layers with a random expression.... you could work a way to manually adjust the position for overlapping layers... so the expression would do 75% of the work, but you'd need to adjust several of the layers that overlap....

to try that, set the layers' positions to 0, 0 and change the last line to:
value + [ x, y ]
you should now be able to move overlapping layers manually.

Kevin Camp
Art Director

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved