Skip to content

Instantly share code, notes, and snippets.

@cyberfly999
Last active June 6, 2023 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberfly999/4429071a5045c484c4f0fdde2631ba41 to your computer and use it in GitHub Desktop.
Save cyberfly999/4429071a5045c484c4f0fdde2631ba41 to your computer and use it in GitHub Desktop.
Easing Equations in JavaScript
// quadratic -----------------------------------------------------------------------------------------
easeInQuad(t, b, c, d) {
t /= d;
return c * t * t + b;
}
easeOutQuad(t, b, c, d) {
t /= d;
return -c * t*(t-2) + b;
};
easeInOutQuad(t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t + b;
t--;
return -c/2 * (t*(t-2) - 1) + b;
};
// cubic -----------------------------------------------------------------------------------------
easeInCubic(t, b, c, d) {
t /= d;
return c * t * t * t + b;
}
easeOutCubic(t, b, c, d) {
t /= d;
t--;
return c*(t*t*t + 1) + b;
};
easeInOutCubic(t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t*t + b;
t -= 2;
return c/2*(t*t*t + 2) + b;
};
// quartic -----------------------------------------------------------------------------------------
easeInQuart(t, b, c, d) {
t /= d;
return c * t * t * t * t + b;
}
easeOutQuart(t, b, c, d) {
t /= d;
t--;
return -c * (t*t*t*t - 1) + b;
};
easeInOutQuart(t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t*t*t + b;
t -= 2;
return -c/2 * (t*t*t*t - 2) + b;
};
// quinitc -----------------------------------------------------------------------------------------
easeInQuint(t, b, c, d) {
t /= d;
return c * t * t * t * t * t + b;
}
easeOutQuint(t, b, c, d) {
t /= d;
t--;
return c*(t*t*t*t*t + 1) + b;
};
easeInOutQuint(t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t*t*t*t + b;
t -= 2;
return c/2*(t*t*t*t*t + 2) + b;
};
// sinusoidal -----------------------------------------------------------------------------------------
easeInSine(t, b, c, d) {
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
}
easeOutSine(t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
};
easeInOutSine(t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
};
// exponential -----------------------------------------------------------------------------------------
easeInExpo(t, b, c, d) {
return c * Math.pow(2, 10 * (t / d - 1)) + b;
}
easeOutExpo(t, b, c, d) {
return c * ( -Math.pow( 2, -10 * t/d ) + 1 ) + b;
};
easeInOutExpo(t, b, c, d) {
t /= d/2;
if (t < 1) return c/2 * Math.pow( 2, 10 * (t - 1) ) + b;
t--;
return c/2 * ( -Math.pow( 2, -10 * t) + 2 ) + b;
};
// circular -----------------------------------------------------------------------------------------
easeInOutCirc(t, b, c, d) {
t /= d/2;
if (t < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
t -= 2;
return c/2 * (Math.sqrt(1 - t*t) + 1) + b;
};
easeInCirc(t, b, c, d) {
t /= d;
return -c * (Math.sqrt(1 - t * t) - 1) + b;
}
easeOutCirc(t, b, c, d) {
t /= d;
t--;
return c * Math.sqrt(1 - t*t) + b;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment