Skip to content

Instantly share code, notes, and snippets.

@7cc
Last active December 18, 2015 16:38
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 7cc/5812302 to your computer and use it in GitHub Desktop.
Save 7cc/5812302 to your computer and use it in GitHub Desktop.
easing, tween
/**
* 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