ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

restricted area for random layers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
cow
Christian Buettner
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


Return to posts index

cow
Alex English
Re: restricted area for random layers
on 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[0] < (thisComp.width - widthleft / 2) && loc[0] > (widthleft / 2))
{
side = (thisComp.width / 2) - loc[0];
if(side < 0)
finalpos[0] = thisComp.width - widthleft / 2 - side * (1 - windowpercent);
else
finalpos[0] = widthleft / 2 - side * (1 - windowpercent);
}
else
finalpos[0] = loc[0];

if(loc[1] < (thisComp.height - heightleft / 2) && loc[1] > (heightleft / 2))
{
side = (thisComp.height / 2) - loc[1];
if(side < 0)
finalpos[1] = thisComp.height - heightleft / 2 - side * (1 - windowpercent);
else
finalpos[1] = heightleft / 2 - side * (1 - windowpercent);
}
else
finalpos[1] = loc[1];
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.



Return to posts index

cow
Christian Buettner
Re: restricted area for random layers
on Jun 16, 2008 at 11:43:54 am

Well ... what worked for you just worked for me!

Thanks a lot, I wouldn´t have figured that out on my own;)


Return to posts index

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