Skip to content

Instantly share code, notes, and snippets.

@pixel-shock
Forked from gre/easing.js
Last active December 16, 2019 14:55
Show Gist options
  • Save pixel-shock/4902d9d8c56bfcff6cfaefb8fbcf2139 to your computer and use it in GitHub Desktop.
Save pixel-shock/4902d9d8c56bfcff6cfaefb8fbcf2139 to your computer and use it in GitHub Desktop.
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the x value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (x) { return x },
// accelerating from zero velocity
easeInQuad: function (x) { return x*x },
// decelerating to zero velocity
easeOutQuad: function (x) { return x*(2-x) },
// acceleration until halfway, then deceleration
easeInOutQuad: function (x) { return x<.5 ? 2*x*x : -1+(4-2*x)*x },
// accelerating from zero velocity
easeInCubic: function (x) { return x*x*x },
// decelerating to zero velocity
easeOutCubic: function (x) { return (--x)*x*x+1 },
// acceleration until halfway, then deceleration
easeInOutCubic: function (x) { return x<.5 ? 4*x*x*x : (x-1)*(2*x-2)*(2*x-2)+1 },
// accelerating from zero velocity
easeInQuart: function (x) { return x*x*x*x },
// decelerating to zero velocity
easeOutQuart: function (x) { return 1-(--x)*x*x*x },
// acceleration until halfway, then deceleration
easeInOutQuart: function (x) { return x<.5 ? 8*x*x*x*x : 1-8*(--x)*x*x*x },
// accelerating from zero velocity
easeInQuint: function (x) { return x*x*x*x*x },
// decelerating to zero velocity
easeOutQuint: function (x) { return 1+(--x)*x*x*x*x },
// acceleration until halfway, then deceleration
easeInOutQuint: function (x) { return x<.5 ? 16*x*x*x*x*x : 1+16*(--x)*x*x*x*x }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment