Pokitto Community Team / Pokittris

Dependencies:   PWMOut Pokitto

Fork of Pokittris by Nicolas Mougin

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers easing.h Source File

easing.h

00001 // t = time, b = start, c = end, d = duration
00002 //float PI = 3.141591;
00003 
00004 float easeInQuad(float t, float b, float c, float d) {
00005     return c*(t/=d)*t + b;
00006 }
00007 float easeOutQuad(float t, float b, float c, float d) {
00008     return -c *(t/=d)*(t-2) + b;
00009 }
00010 float easeInOutQuad(float t, float b, float c, float d) {
00011     if ((t/=d/2) < 1) return c/2*t*t + b;
00012     return -c/2 * ((--t)*(t-2) - 1) + b;
00013 }
00014 float easeInCubic(float t, float b, float c, float d) {
00015     return c*(t/=d)*t*t + b;
00016 }
00017 float easeOutCubic(float t, float b, float c, float d) {
00018     return c*((t=t/d-1)*t*t + 1) + b;
00019 }
00020 float easeInOutCubic(float t, float b, float c, float d) {
00021     if ((t/=d/2) < 1) return c/2*t*t*t + b;
00022     return c/2*((t-=2)*t*t + 2) + b;
00023 }
00024 float easeInQuart(float t, float b, float c, float d) {
00025     return c*(t/=d)*t*t*t + b;
00026 }
00027 float easeOutQuart(float t, float b, float c, float d) {
00028     return -c * ((t=t/d-1)*t*t*t - 1) + b;
00029 }
00030 float easeInOutQuart(float t, float b, float c, float d) {
00031     if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
00032     return -c/2 * ((t-=2)*t*t*t - 2) + b;
00033 }
00034 float easeInQuint(float t, float b, float c, float d) {
00035     return c*(t/=d)*t*t*t*t + b;
00036 }
00037 float easeOutQuint(float t, float b, float c, float d) {
00038     return c*((t=t/d-1)*t*t*t*t + 1) + b;
00039 }
00040 float easeInOutQuint(float t, float b, float c, float d) {
00041     if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
00042     return c/2*((t-=2)*t*t*t*t + 2) + b;
00043 }
00044 float easeInSine(float t, float b, float c, float d) {
00045     return -c * cos(t/d * (PI/2)) + c + b;
00046 }
00047 float easeOutSine(float t, float b, float c, float d) {
00048     return c * sin(t/d * (PI/2)) + b;
00049 }
00050 float easeInOutSine(float t, float b, float c, float d) {
00051     return -c/2 * (cos(PI*t/d) - 1) + b;
00052 }
00053 float easeInExpo(float t, float b, float c, float d) {
00054     return (t==0) ? b : c * pow(2, 10 * (t/d - 1)) + b;
00055 }
00056 float easeOutExpo(float t, float b, float c, float d) {
00057     return (t==d) ? b+c : c * (-pow(2, -10 * t/d) + 1) + b;
00058 }
00059 float easeInOutExpo(float t, float b, float c, float d) {
00060     if (t==0) return b;
00061     if (t==d) return b+c;
00062     if ((t/=d/2) < 1) return c/2 * pow(2, 10 * (t - 1)) + b;
00063     return c/2 * (-pow(2, -10 * --t) + 2) + b;
00064 }
00065 float easeInCirc(float t, float b, float c, float d) {
00066     return -c * (sqrt(1 - (t/=d)*t) - 1) + b;
00067 }
00068 float easeOutCirc(float t, float b, float c, float d) {
00069     return c * sqrt(1 - (t=t/d-1)*t) + b;
00070 }
00071 float easeInOutCirc(float t, float b, float c, float d) {
00072     if ((t/=d/2) < 1) return -c/2 * (sqrt(1 - t*t) - 1) + b;
00073     return c/2 * (sqrt(1 - (t-=2)*t) + 1) + b;
00074 }
00075 float easeInElastic(float t, float b, float c, float d) {
00076     float s=1.70158;float p=0; float a=c;
00077     if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
00078     if (a < abs(c)) { a=c; s=p/4; }
00079     else  s = p/(2*PI) * asin (c/a);
00080     return -(a*pow(2,10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )) + b;
00081 }
00082 float easeOutElastic(float t, float b, float c, float d) {
00083     float s=1.70158;float p=0;float a=c;
00084     if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
00085     if (a < abs(c)) { a=c; s=p/4; }
00086     else s = p/(2*PI) * asin (c/a);
00087     return a*pow(2,-10*t) * sin( (t*d-s)*(2*PI)/p ) + c + b;
00088 }
00089 float easeInOutElastic(float t, float b, float c, float d) {
00090     float s=1.70158;float p=0;float a=c;
00091     if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
00092     if (a < abs(c)) { a=c; s=p/4; }
00093     else s = p/(2*PI) * asin (c/a);
00094     if (t < 1) return -.5*(a*pow(2,10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )) + b;
00095     return a*pow(2,-10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )*.5 + c + b;
00096 }
00097 float easeInBack(float t, float b, float c, float d) {
00098     float s = 1.70158;
00099     return c*(t/=d)*t*((s+1)*t - s) + b;
00100 }
00101 float easeOutBack(float t, float b, float c, float d) {
00102     float s = 1.70158;
00103     return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
00104 }
00105 float easeInOutBack(float t, float b, float c, float d) {
00106     float s = 1.70158; 
00107     if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
00108     return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
00109 }
00110 
00111 float easeOutBounce(float t, float b, float c, float d) {
00112     if ((t/=d) < (1/2.75)) {
00113         return c*(7.5625*t*t) + b;
00114     } else if (t < (2/2.75)) {
00115         return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
00116     } else if (t < (2.5/2.75)) {
00117         return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
00118     } else {
00119         return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
00120     }
00121 }
00122 float easeInBounce(float t, float b, float c, float d) {
00123     return c - easeOutBounce (d-t, 0, c, d) + b;
00124 }
00125 float easeInOutBounce(float t, float b, float c, float d) {
00126     if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b;
00127     return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
00128 }