Last active
April 24, 2023 11:54
-
-
Save monsieuroeuf/6051422 to your computer and use it in GitHub Desktop.
An example of using an Ease and Wizz equation in an expression, without relying on keyframes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function easeandwizz_inOutExpo(t, b, c, d) { | |
if (t==0) return b; | |
if (t==d) return b+c; | |
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; | |
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; | |
} | |
moveDuration = 2; | |
moveStart = inPoint; | |
moveEnd = moveStart+moveDuration; | |
// get the target's x & y values | |
target_x = thisComp.layer("target").transform.position[0]; | |
target_y = thisComp.layer("target").transform.position[1]; | |
// get this layer's starting x & y values | |
start_x = thisLayer.transform.position.valueAtTime(inPoint)[0]; | |
start_y = thisLayer.transform.position.valueAtTime(inPoint)[1]; | |
// calculate the difference between them, i.e. how far to move | |
diff_x = target_x - start_x; | |
diff_y = target_y - start_y; | |
// the Ease and Wizz equation expects time to start at 0 | |
normalisedTime = linear(time, inPoint, inPoint + moveDuration, 0, moveDuration); | |
// figure out x & y independently | |
x = easeandwizz_inOutExpo(normalisedTime, start_x, diff_x, moveDuration); | |
y = easeandwizz_inOutExpo(normalisedTime, start_y, diff_y, moveDuration); | |
[x, y] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment