Skip to content

Instantly share code, notes, and snippets.

@monsieuroeuf
Last active April 24, 2023 11:54
Show Gist options
  • Save monsieuroeuf/6051422 to your computer and use it in GitHub Desktop.
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.
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