Last active
December 18, 2015 16:38
-
-
Save 7cc/5812302 to your computer and use it in GitHub Desktop.
easing, tween
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 | |
* @param t current time | |
* @parm d duartion (total time) | |
* @return 0 - 1 | |
*/ | |
/* | |
weeker | |
Sine | |
Quad | |
Cubic | |
Quart | |
Quint | |
Expo | |
stronger | |
*/ | |
/* ------------------------------------ | |
easeOut | |
------------------------------------*/ | |
// http://upshots.org/actionscript/jsas-understanding-easing | |
function easeOut(t, d) { | |
return 1 - Math.pow(1 - (t / d), 4); | |
} | |
function easeOutQuart(t, d){ | |
return - ((t = t / d - 1) * t * t * t - 1); | |
} | |
/* ------------------------------------ | |
easeInOut | |
------------------------------------*/ | |
function easeInOutQuint(t, d) { | |
var ts=(t/=d)*t; | |
var tc=ts*t; | |
return (6*tc*ts + -15*ts*ts + 10*tc); | |
} | |
function easeInOutQuart(t, d) { | |
var ts = t/d * 2; | |
return (ts < 1 ? Math.pow(ts,4) : -((ts-=2) * Math.pow(ts,3) - 2)) * 1/2; | |
} | |
function easeInOutExpo(t, d) { | |
if (!t) {return 0;} | |
if (t===d) {return 1;} | |
var ts =t/d*2; | |
if (ts < 1) { | |
return Math.pow(2,10* (ts-1)) *1/2; | |
} else { | |
return (-Math.pow(2, -10*--ts) + 2) *1/2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment