ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# restricted area for random layers

FAQ   •   VIEW ALL  restricted area for random layers on Jun 14, 2008 at 1:27:37 pm

Hi again ...

I use this expression for random layer movement at intervals:
x = 10;
f = thisComp.frameDuration * x;
posterizeTime(1 / f);frames
random();
minPos = [0,0];
maxPos = [thisComp.width, thisComp.height];
random(minPos, maxPos);

How can I keep the layer from appearing in a certain area (lets say the middle) of the screen?

again ... many thanks for any insights you can share

Christian  Re: restricted area for random layerson Jun 15, 2008 at 9:09:52 am

The following worked for me. Just set the windowpercent variable to whatever percentage of the area of the comp you want to block out in the center. So, say you need a window in the center that is 20% of the comp width wide and 20% of the comp width tall, you would set windowpercent = 20/100

x = 10;
f = thisComp.frameDuration * x;
posterizeTime(1 / f);
minPos = [0,0];
maxPos = [thisComp.width, thisComp.height];
loc = random(minPos, maxPos);
windowpercent = 50 / 100;
widthleft = thisComp.width * (1 - windowpercent);
heightleft = thisComp.height * (1 - windowpercent);
finalpos = []
if(loc < (thisComp.width - widthleft / 2) && loc > (widthleft / 2))
{
side = (thisComp.width / 2) - loc;
if(side < 0)
finalpos = thisComp.width - widthleft / 2 - side * (1 - windowpercent);
else
finalpos = widthleft / 2 - side * (1 - windowpercent);
}
else
finalpos = loc;

if(loc < (thisComp.height - heightleft / 2) && loc > (heightleft / 2))
{
side = (thisComp.height / 2) - loc;
if(side < 0)
finalpos = thisComp.height - heightleft / 2 - side * (1 - windowpercent);
else
finalpos = heightleft / 2 - side * (1 - windowpercent);
}
else
finalpos = loc;
finalpos;

It seems like there should be a much simpler answer than this, but it's what I came up with. It worked for me to do what I think you were asking for. Hopefully it can serve as a functional base for you to develop what you need.  Re: restricted area for random layerson Jun 16, 2008 at 11:43:54 am