Skip to content

Instantly share code, notes, and snippets.

@MeteC
Created April 7, 2014 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MeteC/10012959 to your computer and use it in GitHub Desktop.
Save MeteC/10012959 to your computer and use it in GitHub Desktop.
This selection of ease curves is awesome for javascript - so I ported them across to C so they can be used in other places (e.g. iOS development). To see the curves in action visit http://easings.net/#
//
// EaseCurves.h
//
//
// Ported from jquery.easing.1.3 by Mete Cakman on 20/08/13.
//
/*
Functions taken from jquery.easing.1.3
To see the curves in action visit http://easings.net/#
For all functions:
t: current time.
b: start value - a start X r Y coordinate of the object being moved
c: total change, should be equal to end value - start value
d: Total duration. i.e. t should lie between [0,d]
e.g. For a quint ease out between 0.0 and 1
float nextZoomValue = easeOutQuint(timeSoFar, 0.0, 1.0, animationZoomInDuration);
*/
inline static double easeInQuad(double t, double b, double c, double d) {
t /= d;
return c*t*t + b;
}
inline static double easeOutQuad(double t, double b, double c, double d) {
t /= d;
return -c *t*(t-2) + b;
}
inline static double easeInOutQuad(double t, double b, double c, double d)
{
if ((t/=d/2) < 1)
{
return c/2*t*t + b;
}
--t;
return -c/2 * (t*(t-2) - 1) + b;
}
inline static double easeInCubic(double t, double b, double c, double d) {
t /= d;
return c*t*t*t + b;
}
inline static double easeOutCubic(double t, double b, double c, double d)
{
t = t/d - 1;
return c*(t*t*t + 1) + b;
}
inline static double easeInOutCubic(double t, double b, double c, double d)
{
if ((t/=d/2) < 1) {
return c/2*t*t*t + b;
}
t-=2;
return c/2*(t*t*t + 2) + b;
}
inline static double easeInQuart(double t, double b, double c, double d) {
t /= d;
return c*t*t*t*t + b;
}
inline static double easeOutQuart(double t, double b, double c, double d) {
t=t/d-1;
return -c * (t*t*t*t - 1) + b;
}
inline static double easeInOutQuart(double t, double b, double c, double d)
{
if ((t/=d/2) < 1) {
return c/2*t*t*t*t + b;
}
t-=2;
return -c/2 * (t*t*t*t - 2) + b;
}
inline static double easeInQuint(double t, double b, double c, double d) {
t/=d;
return c*t*t*t*t*t + b;
}
inline static double easeOutQuint(double t, double b, double c, double d) {
t=t/d-1;
return c*(t*t*t*t*t + 1) + b;
}
inline static double easeInOutQuint(double t, double b, double c, double d)
{
if ((t/=d/2) < 1) {
return c/2*t*t*t*t*t + b;
}
t-=2;
return c/2*(t*t*t*t*t + 2) + b;
}
inline static double easeInSine(double t, double b, double c, double d) {
return -c * cos(t/d * (M_PI_2)) + c + b;
}
inline static double easeOutSine(double t, double b, double c, double d) {
return c * sin(t/d * (M_PI_2)) + b;
}
inline static double easeInOutSine(double t, double b, double c, double d) {
return -c/2 * (cos(M_PI*t/d) - 1) + b;
}
inline static double easeInExpo(double t, double b, double c, double d) {
return (t==0) ? b : c * pow(2, 10 * (t/d - 1)) + b;
}
inline static double easeOutExpo(double t, double b, double c, double d) {
return (t==d) ? b+c : c * (-pow(2, -10 * t/d) + 1) + b;
}
inline static double easeInOutExpo(double t, double b, double c, double d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * pow(2, 10 * (t - 1)) + b;
return c/2 * (-pow(2, -10 * --t) + 2) + b;
}
inline static double easeInCirc(double t, double b, double c, double d)
{
t /= d;
return -c * (sqrt(1 - t*t) - 1) + b;
}
inline static double easeOutCirc(double t, double b, double c, double d)
{
t=t/d-1;
return c * sqrt(1 - t*t) + b;
}
inline static double easeInOutCirc(double t, double b, double c, double d)
{
if ((t/=d/2) < 1) {
return -c/2 * (sqrt(1 - t*t) - 1) + b;
}
t-=2;
return c/2 * (sqrt(1 - t*t) + 1) + b;
}
inline static double easeInElastic(double t, double b, double c, double d)
{
double s=1.70158;
double p=0;
double a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < abs(c)) { a=c; s=p/4; }
else s = p/(2*M_PI) * asin (c/a);
t-=1;
return -(a*pow(2,10*t) * sin( (t*d-s)*(2*M_PI)/p )) + b;
}
inline static double easeOutElastic(double t, double b, double c, double d)
{
double s=1.70158;double p=0;double a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < abs(c)) { a=c; s=p/4; }
else s = p/(2*M_PI) * asin (c/a);
return a*pow(2,-10*t) * sin( (t*d-s)*(2*M_PI)/p ) + c + b;
}
inline static double easeInOutElastic(double t, double b, double c, double d)
{
double s=1.70158;double p=0;double a=c;
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
if (a < abs(c)) { a=c; s=p/4; }
else s = p/(2*M_PI) * asin (c/a);
if (t < 1) {
t-=1;
return -.5*(a*pow(2,10*t) * sin( (t*d-s)*(2*M_PI)/p )) + b;
}
t-=1;
return a*pow(2,-10*t) * sin( (t*d-s)*(2*M_PI)/p )*.5 + c + b;
}
inline static double easeInBack(double t, double b, double c, double d) {
double s = 1.70158;
t/=d;
return c*t*t*((s+1)*t - s) + b;
}
inline static double easeOutBack(double t, double b, double c, double d) {
double s = 1.70158;
t= t/d-1;
return c*(t*t*((s+1)*t + s) + 1) + b;
}
inline static double easeInOutBack(double t, double b, double c, double d)
{
double s = 1.70158;
if ((t/=d/2) < 1) {
s*=(1.525);
return c/2*(t*t*(((s)+1)*t - s)) + b;
}
s*=(1.525);
t-=2;
return c/2*((t)*t*(((s)+1)*t + s) + 2) + b;
}
inline static double easeOutBounce(double t, double b, double c, double d)
{
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
t-=(1.5/2.75);
return c*(7.5625*(t)*t + .75) + b;
} else if (t < (2.5/2.75)) {
t-=(2.25/2.75);
return c*(7.5625*(t)*t + .9375) + b;
} else {
t-=(2.625/2.75);
return c*(7.5625*(t)*t + .984375) + b;
}
}
inline static double easeInBounce(double t, double b, double c, double d) {
return c - easeOutBounce (d-t, 0, c, d) + b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment