Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Scale expression based on rotation

  • Scale expression based on rotation

    Posted by Chris Smith on December 1, 2016 at 9:35 pm

    I have a logo that a client wants me to animate. It’s a ring of figures around a central figure. I can make the ring and make it spin around the central figure easy enough, but the problem is that whomever designed the logo scaled down the figures at the bottom of the circle. If 0 is top and 180 is bottom, when the figures are at 0 they should be 100%, but when they’re at 180 they should be 85% and cycle back up to 100% each rotation forever. I have all the layers parented to a single layer, and when I change the master layer’s rotation they all rotate so they should be able to read their own rotation angle and adjust the scale accordingly, but I don’t know scripting well enough to figure it out. Please help. Thanks!

    Darby Edelen replied 9 years, 5 months ago 3 Members · 2 Replies
  • 2 Replies
  • Walter Soyka

    December 2, 2016 at 11:26 am

    This is a deceptively complicated problem.

    I borrowed some code from a typically brilliant Dan Ebberts’s post [link], and modified it a bit for your request:

    // get the world position of three points;
    // a = a point above the center of the clock, representing 12 o'clock
    // b = the center of the clock
    // c = this layer's anchor point
    a = thisComp.layer("PARENT LAYER").toWorld(thisComp.layer("PARENT LAYER").anchorPoint) - [0,1];
    b = thisComp.layer("PARENT LAYER").toWorld(thisComp.layer("PARENT LAYER").anchorPoint);
    c = thisLayer.toWorld(thisLayer.anchorPoint);

    // figure out the angle between vectors ab and bc
    // this is the relative rotation between this layer and the center
    // in other words, its location on the clock, represented in degrees
    v1 = normalize(a-b);
    v2 = normalize(c-b);
    angle = radiansToDegrees(Math.acos(dot(v1,v2)));
    if (cross(v1,v2)[2] < 0) angle = 360 - angle;

    // adjust the scale according to the angle
    angle = angle % 360;
    if (angle < 180) s = linear(angle, 0, 180, 100, 85) else s = linear (angle, 180, 360, 85, 100);
    [s,s]

    Alt+click the Scale stopwatch for each layer you’d like to be affected, and paste that code in. You’ll need to either rename your rotation-controlling layer to “PARENT LAYER” or replace the references to “PARENT LAYER” in the code above with the name of your own layer.

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

  • Darby Edelen

    December 4, 2016 at 3:51 pm

    Assuming that the layers are parented to the center rotator I think you could use something like this expression on the scale:

    center = parent.toWorld(parent.anchorPoint);
    p = toWorld(anchorPoint);
    v = p - center;
    linear(normalize(v)[1], -1, 1, value, 0.85 * value)

    Darby Edelen

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