Fork of "Pokittris" for the Pokitto
Fork of Pokittris by
easing.h@0:f759a823d3ae, 2017-10-10 (annotated)
- Committer:
- mougino
- Date:
- Tue Oct 10 07:17:45 2017 +0000
- Revision:
- 0:f759a823d3ae
Pokittris 02/10/17 + PokittoLib for compilation on mbed.com
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mougino | 0:f759a823d3ae | 1 | // t = time, b = start, c = end, d = duration |
mougino | 0:f759a823d3ae | 2 | //float PI = 3.141591; |
mougino | 0:f759a823d3ae | 3 | |
mougino | 0:f759a823d3ae | 4 | float easeInQuad(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 5 | return c*(t/=d)*t + b; |
mougino | 0:f759a823d3ae | 6 | } |
mougino | 0:f759a823d3ae | 7 | float easeOutQuad(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 8 | return -c *(t/=d)*(t-2) + b; |
mougino | 0:f759a823d3ae | 9 | } |
mougino | 0:f759a823d3ae | 10 | float easeInOutQuad(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 11 | if ((t/=d/2) < 1) return c/2*t*t + b; |
mougino | 0:f759a823d3ae | 12 | return -c/2 * ((--t)*(t-2) - 1) + b; |
mougino | 0:f759a823d3ae | 13 | } |
mougino | 0:f759a823d3ae | 14 | float easeInCubic(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 15 | return c*(t/=d)*t*t + b; |
mougino | 0:f759a823d3ae | 16 | } |
mougino | 0:f759a823d3ae | 17 | float easeOutCubic(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 18 | return c*((t=t/d-1)*t*t + 1) + b; |
mougino | 0:f759a823d3ae | 19 | } |
mougino | 0:f759a823d3ae | 20 | float easeInOutCubic(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 21 | if ((t/=d/2) < 1) return c/2*t*t*t + b; |
mougino | 0:f759a823d3ae | 22 | return c/2*((t-=2)*t*t + 2) + b; |
mougino | 0:f759a823d3ae | 23 | } |
mougino | 0:f759a823d3ae | 24 | float easeInQuart(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 25 | return c*(t/=d)*t*t*t + b; |
mougino | 0:f759a823d3ae | 26 | } |
mougino | 0:f759a823d3ae | 27 | float easeOutQuart(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 28 | return -c * ((t=t/d-1)*t*t*t - 1) + b; |
mougino | 0:f759a823d3ae | 29 | } |
mougino | 0:f759a823d3ae | 30 | float easeInOutQuart(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 31 | if ((t/=d/2) < 1) return c/2*t*t*t*t + b; |
mougino | 0:f759a823d3ae | 32 | return -c/2 * ((t-=2)*t*t*t - 2) + b; |
mougino | 0:f759a823d3ae | 33 | } |
mougino | 0:f759a823d3ae | 34 | float easeInQuint(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 35 | return c*(t/=d)*t*t*t*t + b; |
mougino | 0:f759a823d3ae | 36 | } |
mougino | 0:f759a823d3ae | 37 | float easeOutQuint(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 38 | return c*((t=t/d-1)*t*t*t*t + 1) + b; |
mougino | 0:f759a823d3ae | 39 | } |
mougino | 0:f759a823d3ae | 40 | float easeInOutQuint(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 41 | if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; |
mougino | 0:f759a823d3ae | 42 | return c/2*((t-=2)*t*t*t*t + 2) + b; |
mougino | 0:f759a823d3ae | 43 | } |
mougino | 0:f759a823d3ae | 44 | float easeInSine(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 45 | return -c * cos(t/d * (PI/2)) + c + b; |
mougino | 0:f759a823d3ae | 46 | } |
mougino | 0:f759a823d3ae | 47 | float easeOutSine(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 48 | return c * sin(t/d * (PI/2)) + b; |
mougino | 0:f759a823d3ae | 49 | } |
mougino | 0:f759a823d3ae | 50 | float easeInOutSine(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 51 | return -c/2 * (cos(PI*t/d) - 1) + b; |
mougino | 0:f759a823d3ae | 52 | } |
mougino | 0:f759a823d3ae | 53 | float easeInExpo(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 54 | return (t==0) ? b : c * pow(2, 10 * (t/d - 1)) + b; |
mougino | 0:f759a823d3ae | 55 | } |
mougino | 0:f759a823d3ae | 56 | float easeOutExpo(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 57 | return (t==d) ? b+c : c * (-pow(2, -10 * t/d) + 1) + b; |
mougino | 0:f759a823d3ae | 58 | } |
mougino | 0:f759a823d3ae | 59 | float easeInOutExpo(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 60 | if (t==0) return b; |
mougino | 0:f759a823d3ae | 61 | if (t==d) return b+c; |
mougino | 0:f759a823d3ae | 62 | if ((t/=d/2) < 1) return c/2 * pow(2, 10 * (t - 1)) + b; |
mougino | 0:f759a823d3ae | 63 | return c/2 * (-pow(2, -10 * --t) + 2) + b; |
mougino | 0:f759a823d3ae | 64 | } |
mougino | 0:f759a823d3ae | 65 | float easeInCirc(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 66 | return -c * (sqrt(1 - (t/=d)*t) - 1) + b; |
mougino | 0:f759a823d3ae | 67 | } |
mougino | 0:f759a823d3ae | 68 | float easeOutCirc(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 69 | return c * sqrt(1 - (t=t/d-1)*t) + b; |
mougino | 0:f759a823d3ae | 70 | } |
mougino | 0:f759a823d3ae | 71 | float easeInOutCirc(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 72 | if ((t/=d/2) < 1) return -c/2 * (sqrt(1 - t*t) - 1) + b; |
mougino | 0:f759a823d3ae | 73 | return c/2 * (sqrt(1 - (t-=2)*t) + 1) + b; |
mougino | 0:f759a823d3ae | 74 | } |
mougino | 0:f759a823d3ae | 75 | float easeInElastic(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 76 | float s=1.70158;float p=0; float a=c; |
mougino | 0:f759a823d3ae | 77 | if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; |
mougino | 0:f759a823d3ae | 78 | if (a < abs(c)) { a=c; s=p/4; } |
mougino | 0:f759a823d3ae | 79 | else s = p/(2*PI) * asin (c/a); |
mougino | 0:f759a823d3ae | 80 | return -(a*pow(2,10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )) + b; |
mougino | 0:f759a823d3ae | 81 | } |
mougino | 0:f759a823d3ae | 82 | float easeOutElastic(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 83 | float s=1.70158;float p=0;float a=c; |
mougino | 0:f759a823d3ae | 84 | if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; |
mougino | 0:f759a823d3ae | 85 | if (a < abs(c)) { a=c; s=p/4; } |
mougino | 0:f759a823d3ae | 86 | else s = p/(2*PI) * asin (c/a); |
mougino | 0:f759a823d3ae | 87 | return a*pow(2,-10*t) * sin( (t*d-s)*(2*PI)/p ) + c + b; |
mougino | 0:f759a823d3ae | 88 | } |
mougino | 0:f759a823d3ae | 89 | float easeInOutElastic(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 90 | float s=1.70158;float p=0;float a=c; |
mougino | 0:f759a823d3ae | 91 | if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); |
mougino | 0:f759a823d3ae | 92 | if (a < abs(c)) { a=c; s=p/4; } |
mougino | 0:f759a823d3ae | 93 | else s = p/(2*PI) * asin (c/a); |
mougino | 0:f759a823d3ae | 94 | if (t < 1) return -.5*(a*pow(2,10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )) + b; |
mougino | 0:f759a823d3ae | 95 | return a*pow(2,-10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )*.5 + c + b; |
mougino | 0:f759a823d3ae | 96 | } |
mougino | 0:f759a823d3ae | 97 | float easeInBack(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 98 | float s = 1.70158; |
mougino | 0:f759a823d3ae | 99 | return c*(t/=d)*t*((s+1)*t - s) + b; |
mougino | 0:f759a823d3ae | 100 | } |
mougino | 0:f759a823d3ae | 101 | float easeOutBack(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 102 | float s = 1.70158; |
mougino | 0:f759a823d3ae | 103 | return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; |
mougino | 0:f759a823d3ae | 104 | } |
mougino | 0:f759a823d3ae | 105 | float easeInOutBack(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 106 | float s = 1.70158; |
mougino | 0:f759a823d3ae | 107 | if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; |
mougino | 0:f759a823d3ae | 108 | return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; |
mougino | 0:f759a823d3ae | 109 | } |
mougino | 0:f759a823d3ae | 110 | |
mougino | 0:f759a823d3ae | 111 | float easeOutBounce(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 112 | if ((t/=d) < (1/2.75)) { |
mougino | 0:f759a823d3ae | 113 | return c*(7.5625*t*t) + b; |
mougino | 0:f759a823d3ae | 114 | } else if (t < (2/2.75)) { |
mougino | 0:f759a823d3ae | 115 | return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; |
mougino | 0:f759a823d3ae | 116 | } else if (t < (2.5/2.75)) { |
mougino | 0:f759a823d3ae | 117 | return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; |
mougino | 0:f759a823d3ae | 118 | } else { |
mougino | 0:f759a823d3ae | 119 | return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; |
mougino | 0:f759a823d3ae | 120 | } |
mougino | 0:f759a823d3ae | 121 | } |
mougino | 0:f759a823d3ae | 122 | float easeInBounce(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 123 | return c - easeOutBounce (d-t, 0, c, d) + b; |
mougino | 0:f759a823d3ae | 124 | } |
mougino | 0:f759a823d3ae | 125 | float easeInOutBounce(float t, float b, float c, float d) { |
mougino | 0:f759a823d3ae | 126 | if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b; |
mougino | 0:f759a823d3ae | 127 | return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b; |
mougino | 0:f759a823d3ae | 128 | } |