-
-
Save opatut/1f11a905ac1b660d9f8e to your computer and use it in GitHub Desktop.
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
/* | |
* Easing Functions - inspired from http://gizma.com/easing/ | |
* only considering the t value for the range [0, 1] => [0, 1] | |
* Finally! Someone who understands we don't need to put the | |
* start, end, duration, etc. into the easing forumlae. | |
*/ | |
var EasingFunctions = { | |
// no easing, no acceleration | |
linear: function (t) { return t }, | |
// accelerating from zero velocity | |
easeInQuad: function (t) { return t*t }, | |
// decelerating to zero velocity | |
easeOutQuad: function (t) { return t*(2-t) }, | |
// acceleration until halfway, then deceleration | |
easeInOutQuad: function (t) { return t<.5 ? 2*t*t : -1+(4-2*t)*t }, | |
// accelerating from zero velocity | |
easeInCubic: function (t) { return t*t*t }, | |
// decelerating to zero velocity | |
easeOutCubic: function (t) { return (--t)*t*t+1 }, | |
// acceleration until halfway, then deceleration | |
easeInOutCubic: function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 }, | |
// accelerating from zero velocity | |
easeInQuart: function (t) { return t*t*t*t }, | |
// decelerating to zero velocity | |
easeOutQuart: function (t) { return 1-(--t)*t*t*t }, | |
// acceleration until halfway, then deceleration | |
easeInOutQuart: function (t) { return t<.5 ? 8*t*t*t*t : 1-8*(--t)*t*t*t }, | |
// accelerating from zero velocity | |
easeInQuint: function (t) { return t*t*t*t*t }, | |
// decelerating to zero velocity | |
easeOutQuint: function (t) { return 1+(--t)*t*t*t*t }, | |
// acceleration until halfway, then deceleration | |
easeInOutQuint: function (t) { return t<.5 ? 16*t*t*t*t*t : 1+16*(--t)*t*t*t*t }, | |
// accelerating from zero velocity | |
easeInSine: function (t) { return -1*Math.cos(t*(Math.PI/2))+1 }, | |
// decelerating to zero velocity | |
easeOutSine: function (t) { return 1*Math.sin(t*(Math.PI/2)) }, | |
// accelerating until halfway, then decelerating | |
easeInOutSine: function (t) { return -0.5*(Math.cos(Math.PI*t)-1) }, | |
// accelerating from zero velocity | |
easeInExpo: function (t) { return 1*Math.pow(2, 10*(t-1)) }, | |
// decelerating to zero velocity | |
easeOutExpo: function (t) { return 1*(-Math.pow(2, -10*t)+1 ) }, | |
// accelerating until halfway, then decelerating | |
easeInOutExpo: function (t) { t /= 0.5; if (t < 1) return 0.5 * Math.pow(2, 10*(t-1)); t--; return 0.5 * (-Math.pow(2, -10*t)+2); }, | |
// accelerating from zero velocity | |
easeInCirc: function (t) { return -1*(Math.sqrt(1-t*t)-1) }, | |
// decelerating to zero velocity | |
easeOutCirc: function (t) { t--; return 1*Math.sqrt(1-t*t); }, | |
// acceleration until halfway, then deceleration | |
easeInOutCirc: function (t) { t /= 0.5; if(t<1) { return -0.5*(Math.sqrt(1-t*t)-1); }else{ t-=2; return 0.5*(Math.sqrt(1-t*t)+1); } } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment