FORUMS: list search recent posts

# Scale expression based on rotation

FAQ   •   VIEW ALL
 Scale expression based on rotation on Dec 1, 2016 at 9:35:37 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!

 Re: Scale expression based on rotationon Dec 2, 2016 at 11:26:37 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
Motion Graphics, Widescreen Events, Presentation Design, and Consulting

 Re: Scale expression based on rotationon Dec 4, 2016 at 3:51:42 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