Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions restricted area for random layers

  • restricted area for random layers

    Posted by Christian Buettner on June 14, 2008 at 1:27 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

    Christian Buettner replied 17 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Alex English

    June 15, 2008 at 9:09 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.

  • Christian Buettner

    June 16, 2008 at 11:43 am

    Well … what worked for you just worked for me!

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

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