运动函数
参数
t
已经运动的时间
b
起始数值
c
运动距离
d
总共运动的时间
namespace ease { const real PI = 3.14159265358979323846264338327950288; real linear( real t, real b, real c, real d) { return (t/d)*c + b; } real in_quad( real t, real b, real c, real d ) { return c*(t/=d)*t + b; } real out_quad( real t, real b, real c, real d ) { return -c *(t/=d)*(t-2) + b; } real in_out_quad( real t, real b, real c, real d ) { if ((t/=d/2) < 1) return c/2*t*t + b; return -c/2 * ((--t)*(t-2) - 1) + b; } real in_cubic( real t, real b, real c, real d ) { return c*(t/=d)*t*t + b; } real out_cubic( real t, real b, real c, real d) { return c*((t=t/d-1)*t*t + 1) + b; } real in_out_cubic( real t, real b, real c, real d) { if ((t/=d/2) < 1) return c/2*t*t*t + b; return c/2*((t-=2)*t*t + 2) + b; } real in_quart( real t, real b, real c, real d) { return c*(t/=d)*t*t*t + b; } real out_quart ( real t, real b, real c, real d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; } real in_out_quart ( real t, real b, real c, real d) { if ((t/=d/2) < 1) return c/2*t*t*t*t + b; return -c/2 * ((t-=2)*t*t*t - 2) + b; } real in_quint ( real t, real b, real c, real d) { return c*(t/=d)*t*t*t*t + b; } real out_quint ( real t, real b, real c, real d) { return c*((t=t/d-1)*t*t*t*t + 1) + b; } real in_out_quint( real t, real b, real c, real d) { if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; return c/2*((t-=2)*t*t*t*t + 2) + b; } real in_sine( real t, real b, real c, real d) { return -c * cos(t/d * (PI/2)) + c + b; } real out_sine( real t, real b, real c, real d) { return c * sin(t/d * (PI/2)) + b; } real in_out_sine( real t, real b, real c, real d) { return -c/2 * (cos(PI*t/d) - 1) + b; } real in_expo( real t, real b, real c, real d) { return (t==0) ? b : c * pow(2, 10 * (t/d - 1)) + b; } real out_expo( real t, real b, real c, real d) { return (t==d) ? b+c : c * (-pow(2, -10 * t/d) + 1) + b; } real in_out_expo( real t, real b, real c, real 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; } real in_circ( real t, real b, real c, real d) { return -c * (sqrt(1 - (t/=d)*t) - 1) + b; } real out_circ( real t, real b, real c, real d) { return c * sqrt(1 - (t=t/d-1)*t) + b; } real in_out_circ( real t, real b, real c, real d) { if ((t/=d/2) < 1) return -c/2 * (sqrt(1 - t*t) - 1) + b; return c/2 * (sqrt(1 - (t-=2)*t) + 1) + b; } real in_elastic( real t, real b, real c, real d) { real s=1.70158; real p=0; real 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*PI) * asin (c/a); return -(a*pow(2,10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )) + b; } real out_elastic( real t, real b, real c, real d) { real s=1.70158;real p=0;real 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*PI) * asin (c/a); return a*pow(2,-10*t) * sin( (t*d-s)*(2*PI)/p ) + c + b; } real in_out_elastic( real t, real b, real c, real d) { real s=1.70158;real p=0;real 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*PI) * asin (c/a); if (t < 1) return -.5*(a*pow(2,10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )) + b; return a*pow(2,-10*(t-=1)) * sin( (t*d-s)*(2*PI)/p )*.5 + c + b; } real in_back( real t, real b, real c, real d) { real s = 1.70158; return c*(t/=d)*t*((s+1)*t - s) + b; } real out_back( real t, real b, real c, real d) { real s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; } real in_out_back( real t, real b, real c, real d) { real s = 1.70158; if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; } real in_back_x( real t, real b, real c, real d) { real s = 1.70158 * 2; return c*(t/=d)*t*((s+1)*t - s) + b; } real out_back_x( real t, real b, real c, real d) { real s = 1.70158 * 2; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; } real in_out_back_x( real t, real b, real c, real d) { real s = 1.70158 * 2; if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; } real in_back_xx( real t, real b, real c, real d) { real s = 1.70158 * 3; return c*(t/=d)*t*((s+1)*t - s) + b; } real out_back_xx( real t, real b, real c, real d) { real s = 1.70158 * 3; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; } real in_out_back_xx( real t, real b, real c, real d) { real s = 1.70158 * 3; if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; } real out_bounce( real t, real b, real c, real d) { if ((t/=d) < (1/2.75)) return c*(7.5625*t*t) + b; else if (t < (2/2.75)) return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; else if (t < (2.5/2.75)) return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; else return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; } real in_bounce( real t, real b, real c, real d) { return c - out_bounce ( d-t, 0, c, d) + b; } real in_out_bounce( real t, real b, real c, real d) { if (t < d/2) return in_bounce ( t*2, 0, c, d ) * .5 + b; return out_bounce ( t*2-d, 0, c, d ) * .5 + c*.5 + b; } function *get_ease_func(const ustring& name) { static hash_table<ustring,function*> tbl; if(tbl.size() == 0) { tbl[L"linear"] = &linear; tbl[L"quad-in"] = &in_quad; tbl[L"quad-out"] = &out_quad; tbl[L"quad-in-out"] = &in_out_quad; tbl[L"cubic-in"] = &in_cubic; tbl[L"cubic-out"] = &out_cubic; tbl[L"cubic-in-out"] = &in_out_cubic; tbl[L"quart-in"] = &in_quart; tbl[L"quart-out"] = &out_quart ; tbl[L"quart-in-out"] = &in_out_quart ; tbl[L"quint-in"] = &in_quint ; tbl[L"quint-out"] = &out_quint ; tbl[L"quint-in-out"] = &in_out_quint; tbl[L"sine-in"] = &in_sine; tbl[L"sine-out"] = &out_sine; tbl[L"sine-in-out"] = &in_out_sine; tbl[L"expo-in"] = &in_expo; tbl[L"expo-out"] = &out_expo; tbl[L"expo-in-out"] = &in_out_expo; tbl[L"circ-in"] = &in_circ; tbl[L"circ-out"] = &out_circ; tbl[L"circ-in-out"] = &in_out_circ; tbl[L"elastic-in"] = &in_elastic; tbl[L"elastic-out"] = &out_elastic; tbl[L"elastic-in-out"] = &in_out_elastic; tbl[L"back-in"] = &in_back; tbl[L"back-out"] = &out_back; tbl[L"back-in-out"] = &in_out_back; tbl[L"x-back-in"] = &in_back_x; tbl[L"x-back-out"] = &out_back_x; tbl[L"x-back-in-out"] = &in_out_back_x; tbl[L"xx-back-in"] = &in_back_xx; tbl[L"xx-back-out"] = &out_back_xx; tbl[L"xx-back-in-out"] = &in_out_back_xx; tbl[L"bounce-in"] = &out_bounce; tbl[L"bounce-out"] = &in_bounce; tbl[L"bounce-in-out"] = &in_out_bounce; } function* pf = 0; tbl.find(name,pf); return pf; } }