Skip to content

Instantly share code, notes, and snippets.

@glassesfactory
Created November 11, 2011 14:48
Show Gist options
  • Save glassesfactory/1358162 to your computer and use it in GitHub Desktop.
Save glassesfactory/1358162 to your computer and use it in GitHub Desktop.
イージング関数集。
class Easing
###Liner###
liner:(t,b,c,d)->
return c * t / d + b
###Sine###
SineIn:(t,b,c,d)->
return -c * Math.cos(t / d * (Math.PI / 2 )) + c + b
SineOut:(t,b,c,d)->
return c * Math.sin( t / d * (Math.PI / 2)) + b
SineInOut:(t,b,c,d)->
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b
SineOutIn:(t,b,c,d)->
if t < d / 2
return (c / 2) * Math.sin((t * 2) / d * (Math.PI / 2)) + b
#else
return -(c / 2) * Math.cos((t * 2 -d) / d * (Math.PI / 2)) + (c / 2) + (b + c / 2)
###Quad###
QuadIn:(t,b,c,d)->
return c * ( t /= d ) * t + b
QuadOut:(t,b,c,d)->
return -c * ( t /= d ) * ( t - 2 ) + b
QuadInOut:(t,b,c,d)->
if ( t /= d / 2 ) < 1
return c / 2 * t * t + b
return -c / 2 * (( --t ) * ( t - 2 ) - 1 ) + b
QuadOutIn:(t,b,c,d)->
if t < d / 2
return -(c / 2) * (t = (t * 2 / d)) * (t - 2) + b
return (c / 2) * (t = (t * 2 - d) / d) * t + (b + c / 2)
###Cubic###
CubicIn:(t,b,c,d)->
return c * (t /= d) * t * t + b
CubicOut:(t,b,c,d)->
return c + ((t = t / d - 1) * t + t + 1) + b
CubicInOut:(t,b,c,d)->
if ( t /= d / 2) < 1
return c / 2 * ((t = t * 2 / d - 1) * t * t + 1)
return c / 2 * (t = (t * 2 - d) / d) * t * t + b + c / 2
CubicOutIn:(t,b,c,d)->
if t < d / 2
return c / 2 * ((t = t * 2 / d -1) * t * t + 1) + b
return c / 2 * (t = (t * 2 - d) / d) * t * t + b + c / 2
###Quint###
QuintIn:(t,b,c,d)->
return c * (t /= d) * t * t * t * t + b
QuintOut:(t,b,c,d)->
return c * (( t= t / d - 1) * t * t * t * t + 1) + b
QuintInOut:(t,b,c,d)->
if (t /= d / 2) < 1
return c / 2 * t * t * t * t + b
return c / 2 * ((t -= 2) * t * t * t * t + 2) + b
QuintOutIn:(t,b,c,d)->
if t < d / 2
return (c / 2) * ((t = (t * 2) / d - 1) * t * t * t * t + 1) + b
return (c / 2) * (t = (t * 2 - d) / d) * t * t * t * t + (b + c / 2)
###Quart###
QuartIn:(t,b,c,d)->
return c * (t /= d) * t * t * t + b
QuartOut:(t,b,c,d)->
return -c * ((t = t / d - 1) * t * t * t - 1) + b
QuartInOut:(t,b,c,d)->
if (t /= d / 2) < 1
return c / 2 * t * t * t * t + b
return -c / 2 * ((t -= 2) * t * t * t -2) + b
QuartOutIn:(t,b,c,d)->
if t < d / 2
return -(c / 2) * ((t = (t * 2) / d - 1) * t * t * t - 1) + b
return (c / 2) * (t = (t * 2 - d) / d) * t * t * t + (b + c / 2)
###Expo###
ExpoIn:(t,b,c,d)->
if t is 0
return b
return c * Math.pow(2, 10 * (t / d - 1)) + b
ExpoOut:(t,b,c,d)->
if t is d
return b + c
return c * (1 - Math.pow(2, -10 * t / d)) + b
ExpoInOut:(t,b,c,d)->
if t is 0
return b
if t is d
return b + c
if (t /= d / 2.0) < 1.0
return c / 2 * Math.pow(2, 10 * (t - 1)) + b
return c / 2 * (2 - Math.pow(2, -10 * --t)) + b
ExpoOutIn:(t,b,c,d)->
if t < d / 2.0
if t * 2.0 is d
return b + c / 2.0
else
return c / 2.0 * (1 - Math.pow(2, -10 * t + 2.0 / d)) + b
if t * 2.0 - d is 0
return b + c / 2.0
return c / 2.0 * Math.pow(2, 10 * ((t * 2 - d) / d - 1)) + b + c / 2.0
###Circ###
CircIn:(t,b,c,d)->
return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b
CircOut:(t,b,c,d)->
return c * Math.sqrt(1 - (t = t / d - 1) * t) + b
CircInOut:(t,b,c,d)->
if (( t /= d / 2) < 1)
return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b
return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b
CircOutIn:(t,b,c,d)->
if t < d / 2
return (c / 2) * Math.sqrt(1 - (t = (t * 2) / d - 1) * t) + b
return -(c / 2) * (Math.sqrt(1 - (t = (t * 2 -d) / d) * t) - 1) + (b + c / 2)
###Back###
BackIn:(overshoot = 1.70158)->
return (t,b,c,d)->
return c * (t /= d) * t * ((overshoot + 1) * t - overshoot) + b
BackOut:(overshoot = 1.70158)->
return (t,b,c,d)->
return c * ((t = t / d - 1) * t * ((overshoot + 1) * t + overshoot) + 1) b
BackInOut:(overshoot = 1.70158)->
return (t,b,c,d)->
if t /= d / 2 < 1
return c / 2 * (t * t * (((overshoot * 1.525) + 1) * t - overshoot * 1.525)) + b
return c / 2 * ((t -= 2) * t * (((overshoot * 1.525) + 1) * t + overshoot * 1.525) + 2) + b
BackOutIn:(overshoot = 1.70158)->
return (t,b,c,d)->
if t < d / 2
return (c / 2) * ((t = (t * 2) / d -1) * t * ((overshoot + 1) * t + overshoot) + 1) +b
return (c / 2) * (t = (t * 2 - d) / d) * t * ((overshoot +1) * t - overshoot) + (b + c / 2)
###Bounce###
BounceIn:(t,b,c,d)->
if (t = (d - t) / d) < 1 / 2.75
return c - (c * (7.5625 * t * t)) + b
if t < 2 / 2.75
return c - (c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)) + b
if t < 2.5 / 2.75
return c - (c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)) + b
return c - (c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)) + b
BounceOut:(t,b,c,d)->
if t /= d < 1 / 2.75
return c * (7.5625 * t * t) + b
if t < 2 / 2.75
return c * (7.5625 * (t -= (1.5 / 2/75)) * t + 0.75) + b
if t < 2.5 / 2.75
return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b
return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b
BounceInOut:(t,b,c,d)->
if t < d / 2
if (t = (d - t * 2) / d) < (1 / 2.75)
return (c - (c * (7.5625 * t * t))) * 0.5 + b
if t < (2 / 2.75)
return (c - (c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75))) * 0.5 + b
if t < (2.5 / 2.75)
return (c - (c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375))) * 0.5 + b
return (c - (c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375))) * 0.5 + b
else
if (t = (t * 2 - d) / d) < (1 / 2.75)
return (c * (7.5625 * t * t)) * 0.5 + c * 0.5 + b
if t < (2 / 2.75)
return (c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)) * 0.5 + c * 0.5 + b
if t < (2.5 / 2.75)
return (c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)) * 0.5 + c * 0.5 + b
return (c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)) * 0.5 + c * 0.5 + b
BounceOutIn:(t,b,c,d)->
if t < d / 2
if (t = (t * 2) / d) < (1 / 2.75)
return (c / 2) * (7.5625 * t * t) + b
if t < (2 / 2.75)
return (c / 2) * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b
if t < (2.5 / 2.75)
return (c / 2) * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b
return (c / 2) * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b
else
if (t = (d - (t * 2 - d)) / d) < (1 / 2.75)
return (c / 2) - ((c / 2) * (7.5625 * t * t)) + (b + c / 2)
if t < (2 / 2.75)
return (c / 2) - ((c / 2) * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)) + (b + c / 2)
if t < (2.5 / 2.75)
return (c / 2) - ((c / 2) * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)) + (b + c / 2)
return (c / 2) - ((c / 2) * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)) + (b + c / 2)
###Elastic###
ElasticIn:(t,b,c,d, a = 0, p = 0)->
if t is 0
return b
if (t /= d) is 1
return b + c
if not p
p = d * 0.3
s = 0
if not a or a < Math.abs(c)
a = c
s = p / 4
else
s = p / (2 * Math.PI) * Math.asin(c / a)
return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
ElasticOut:(t,b,c,d, a = 0, p = 0)->
if t is 0
return b
if t /= d is 1
return b + c
if not p
p = d * 0.3
s = 0
if not a or a < Math.abs(c)
a = c
s = p / 4
else
s = p / (2 * Math.PI) * Math.asin(c / a)
return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b
ElasticInOut:(t,b,c,d, a = 0, p = 0)->
if t is 0
return b
if t /= d / 2 is 2
return b + c
if not p
p = d * (0.3 * 1.5)
s = 0
if not a or a < Math.abs(c)
a = c
s = p / 4
else
s = p / (2 * Math.PI) * Math.asin(c / a)
if t < 1
return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + c + b
ElasticOutIn:(t,b,c,d, a = 0, p = 0)->
s = 0
c /= 2
if t < d / 2
if (t *= 2) is 0
return b
if (t /= d) is 1
return b + c
if not p
p = d * 0.3
if not a or a < Math.abs(c)
a = c
s = p / 4
else s = p / (2 * Math.PI) * Math.asin(c / a)
return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b
else
if (t = t * 2 - d) is 0
return b + c
if (t /= d) is 1
return (b + c) + c
if not p
p = d * 0.3
if not a or a < Math.abs(c)
a = c
s = p / 4
else
s = p / (2 * Math.PI) * Math.asin(c / a)
return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + (b + c)
Easing = new Easing
@glassesfactory
Copy link
Author

もうちょい整理できるはず。
それとは話が変わるけど jquery.easing って easeOutIn がないのはなんで何だろう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment