Skip to content

Instantly share code, notes, and snippets.

@rjmoggach
Created July 17, 2019 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjmoggach/88ae72e92d0d52542543f30b87f32b1f to your computer and use it in GitHub Desktop.
Save rjmoggach/88ae72e92d0d52542543f30b87f32b1f to your computer and use it in GitHub Desktop.
After Effects Easing Functions
function easeExpo(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeExpo(beginValue[0], endValue[0], duration, offset);
y = easeExpo(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeExpo(beginValue[0], endValue[0], duration, offset);
y = easeExpo(beginValue[1], endValue[1], duration, offset);
z = easeExpo(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration / 2;
if (t < 1) return (c / 2) * Math.pow(2, 10 * (t - 1)) + beginValue;
t--;
return (c / 2) * (-Math.pow(2, -10 * t) + 2) + beginValue;
}
function easeCirc(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeCirc(beginValue[0], endValue[0], duration, offset);
y = easeCirc(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeCirc(beginValue[0], endValue[0], duration, offset);
y = easeCirc(beginValue[1], endValue[1], duration, offset);
z = easeCirc(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration / 2;
if (t < 1) return (-c / 2) * (Math.sqrt(1 - t * t) - 1) + beginValue;
t -= 2;
return (c / 2) * (Math.sqrt(1 - t * t) + 1) + beginValue;
}
function easeQuart(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeQuart(beginValue[0], endValue[0], duration, offset);
y = easeQuart(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeQuart(beginValue[0], endValue[0], duration, offset);
y = easeQuart(beginValue[1], endValue[1], duration, offset);
z = easeQuart(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration / 2;
if (t < 1) return (c / 2) * t * t * t * t + beginValue;
t -= 2;
return (-c / 2) * (t * t * t * t - 2) + beginValue;
}
function easeExpoIn(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeExpoIn(beginValue[0], endValue[0], duration, offset);
y = easeExpoIn(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeExpoIn(beginValue[0], endValue[0], duration, offset);
y = easeExpoIn(beginValue[1], endValue[1], duration, offset);
z = easeExpoIn(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration;
return c * Math.pow(2, 10 * (t - 1)) + beginValue;
}
function easeCircIn(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeCircIn(beginValue[0], endValue[0], duration, offset);
y = easeCircIn(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeCircIn(beginValue[0], endValue[0], duration, offset);
y = easeCircIn(beginValue[1], endValue[1], duration, offset);
z = easeCircIn(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration;
return -c * (Math.sqrt(1 - t * t) - 1) + beginValue;
}
function easeQuartIn(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeQuartIn(beginValue[0], endValue[0], duration, offset);
y = easeQuartIn(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeQuartIn(beginValue[0], endValue[0], duration, offset);
y = easeQuartIn(beginValue[1], endValue[1], duration, offset);
z = easeQuartIn(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration;
return c * t * t * t * t + beginValue;
}
function easeExpoOut(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeExpoOut(beginValue[0], endValue[0], duration, offset);
y = easeExpoOut(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeExpoOut(beginValue[0], endValue[0], duration, offset);
y = easeExpoOut(beginValue[1], endValue[1], duration, offset);
z = easeExpoOut(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration;
return c * (-Math.pow(2, -10 * t) + 1) + beginValue;
}
function easeCircOut(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeCircOut(beginValue[0], endValue[0], duration, offset);
y = easeCircOut(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeCircOut(beginValue[0], endValue[0], duration, offset);
y = easeCircOut(beginValue[1], endValue[1], duration, offset);
z = easeCircOut(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration;
t--;
return c * Math.sqrt(1 - t * t) + beginValue;
}
function easeQuartOut(beginValue, endValue, duration, offset) {
t = time - offset;
if (t < 0) return beginValue;
if (t > duration) return endValue;
if (beginValue.constructor == Array) {
x = 0;
y = 0;
z = 0;
if (beginValue.length == 2) {
x = easeQuartOut(beginValue[0], endValue[0], duration, offset);
y = easeQuartOut(beginValue[1], endValue[1], duration, offset);
return [x, y];
} else {
x = easeQuartOut(beginValue[0], endValue[0], duration, offset);
y = easeQuartOut(beginValue[1], endValue[1], duration, offset);
z = easeQuartOut(beginValue[2], endValue[2], duration, offset);
return [x, y, z];
}
}
c = endValue - beginValue;
t /= duration;
t--;
return -c * (t * t * t * t - 1) + beginValue;
}
function scaleToFit(a, b) {
myW = thisLayer.sourceRectAtTime(thisComp.duration / 2).width;
myH = thisLayer.sourceRectAtTime(thisComp.duration / 2).height;
calcW = (a / myW) * 100;
calcH = (b / myH) * 100;
lowest = calcW;
calcH < calcW && (lowest = calcH);
return [lowest, lowest];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment