moduleMath class << self defpow(val, times) return val ** times end end end moduleEase class << self deflinear(t, b, c, d) return c * t / d + b end
definQuad(t, b, c, d) t = t / d p Math.pow(t, 2) return c * Math.pow(t, 2) + b end
defoutQuad(t, b, c, d) t = t / d return -c * t * (t - 2) + b end
definOutQuad(t, b, c, d) t = t / d * 2 if t < 1 return c / 2 * Math.pow(t, 2) + b else return -c / 2 * ((t - 1) * (t - 3) - 1) + b end end
defoutInQuad(t, b, c, d) if t < d / 2 return outQuad(t * 2, b, c / 2, d) else return inQuad((t * 2) - d, b + c / 2, c / 2, d) end end
definCubic(t, b, c, d) t = t / d return c * Math.pow(t, 3) + b end
defoutCubic(t, b, c, d) t = t / d - 1 return c * (Math.pow(t, 3) + 1) + b end
definOutCubic(t, b, c, d) t = t / d * 2 if t < 1 return c / 2 * t * t * t + b else t = t - 2 return c / 2 * (t * t * t + 2) + b end end
defoutInCubic(t, b, c, d) if t < d / 2 return outCubic(t * 2, b, c / 2, d) else return inCubic((t * 2) - d, b + c / 2, c / 2, d) end end
definQuart(t, b, c, d) t = t / d return c * Math.pow(t, 4) + b end
defoutQuart(t, b, c, d) t = t / d - 1 return -c * (Math.pow(t, 4) - 1) + b end
definOutQuart(t, b, c, d) t = t / d * 2 if t < 1 return c / 2 * Math.pow(t, 4) + b else t = t - 2 return -c / 2 * (Math.pow(t, 4) - 2) + b end end
defoutInQuart(t, b, c, d) if t < d / 2 return outQuart(t * 2, b, c / 2, d) else return inQuart((t * 2) - d, b + c / 2, c / 2, d) end end
definQuint(t, b, c, d) t = t / d return c * Math.pow(t, 5) + b end
defoutQuint(t, b, c, d) t = t / d - 1 return c * (Math.pow(t, 5) + 1) + b end
definOutQuint(t, b, c, d) t = t / d * 2 if t < 1 return c / 2 * Math.pow(t, 5) + b else t = t - 2 return c / 2 * (Math.pow(t, 5) + 2) + b end end
defoutInQuint(t, b, c, d) if t < d / 2 return outQuint(t * 2, b, c / 2, d) else return inQuint((t * 2) - d, b + c / 2, c / 2, d) end end
definSine(t, b, c, d) return -c * Math.cos(t / d * (Math::PI / 2)) + c + b end
defoutSine(t, b, c, d) return c * Math.sin(t / d * (Math::PI / 2)) + b end
definOutSine(t, b, c, d) return -c / 2 * (Math.cos(Math::PI * t / d) - 1) + b end
defoutInSine(t, b, c, d) if t < d / 2 return outSine(t * 2, b, c / 2, d) else return inSine((t * 2) -d, b + c / 2, c / 2, d) end end
definExpo(t, b, c, d) if t == 0 return b else return c * Math.pow(2, 10 * (t / d - 1)) + b - c * 0.001 end end
defoutExpo(t, b, c, d) if t == d return b + c else return c * 1.001 * (-Math.pow(2, -10 * t / d) + 1) + b end end
definOutExpo(t, b, c, d) return b if t == 0 return b + c if t == d t = t / d * 2 if t < 1 return c / 2 * Math.pow(2, 10 * (t - 1)) + b - c * 0.0005 else t = t - 1 return c / 2 * 1.0005 * (-Math.pow(2, -10 * t) + 2) + b end end
defoutInExpo(t, b, c, d) if t < d / 2 return outExpo(t * 2, b, c / 2, d) else return inExpo((t * 2) - d, b + c / 2, c / 2, d) end end
definCirc(t, b, c, d) t = t / d return(-c * (Math.sqrt(1 - Math.pow(t, 2)) - 1) + b) end
defoutCirc(t, b, c, d) t = t / d - 1 return(c * Math.sqrt(1 - Math.pow(t, 2)) + b) end
definOutCirc(t, b, c, d) t = t / d * 2 if t < 1 return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b else t = t - 2 return c / 2 * (Math.sqrt(1 - t * t) + 1) + b end end
defoutInCirc(t, b, c, d) if t < d / 2 return outCirc(t * 2, b, c / 2, d) else return inCirc((t * 2) - d, b + c / 2, c / 2, d) end end
definElastic(t, b, c, d, a, p=nil) returnif t == 0
t = t / d
return b + c if t == 1
p = d * 0.3ifnot p
s = 0
ifnot a or a < (c).abs a = c s = p / 4 else s = p / (2 * Math::PI) * Math.asin(c/a) end
t = t - 1
return -(a * Math.pow(2, 10 * t) * Math.sin((t * d - s) * (2 * Math::PI) / p)) + b end
# a: amplitud # p: period defoutElastic(t, b, c, d, a, p=nil) return b if t == 0
t = t / d
return b + c if t == 1
p = d * 0.3ifnot p
s = 0
ifnot a or a < (c).abs a = c s = p / 4 else s = p / (2 * Math::PI) * Math.asin(c/a) end
return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math::PI) / p) + c + b end
# p = period # a = amplitud definOutElastic(t, b, c, d, a=nil, p=nil) return b if t == 0
t = t / d * 2
return b + c if t == 2
p = d * (0.3 * 1.5) ifnot p a = 0ifnot a
s = 0
ifnot a or a < (c).abs a = c s = p / 4 else s = p / (2 * Math::PI) * Math.asin(c / a) end
if t < 1 t = t - 1 return -0.5 * (a * Math.pow(2, 10 * t) * Math.sin((t * d - s) * (2 * Math::PI) / p)) + b else t = t - 1 return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math::PI) / p ) * 0.5 + c + b end end
# a: amplitud # p: period defoutInElastic(t, b, c, d, a, p=nil) if t < d / 2 return outElastic(t * 2, b, c / 2, d, a, p) else return inElastic((t * 2) - d, b + c / 2, c / 2, d, a, p) end end
definBack(t, b, c, d, s=nil) s = 1.70158ifnot s t = t / d return c * t * t * ((s + 1) * t - s) + b end
defoutBack(t, b, c, d, s=nil) s = 1.70158ifnot s t = t / d - 1 return c * (t * t * ((s + 1) * t + s) + 1) + b end
definOutBack(t, b, c, d, s=nil) s = 1.70158ifnot s s = s * 1.525 t = t / d * 2 if t < 1 return c / 2 * (t * t * ((s + 1) * t - s)) + b else t = t - 2 return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b end end
defoutInBack(t, b, c, d, s) if t < d / 2 return outBack(t * 2, b, c / 2, d, s) else return inBack((t * 2) - d, b + c / 2, c / 2, d, s) end end
defoutBounce(t, b, c, d) t = t / d if t < 1 / 2.75 return c * (7.5625 * t * t) + b elseif t < 2 / 2.75 t = t - (1.5 / 2.75) return c * (7.5625 * t * t + 0.75) + b elseif t < 2.5 / 2.75 t = t - (2.25 / 2.75) return c * (7.5625 * t * t + 0.9375) + b else t = t - (2.625 / 2.75) return c * (7.5625 * t * t + 0.984375) + b end end
definBounce(t, b, c, d) return c - outBounce(d - t, 0, c, d) + b end
definOutBounce(t, b, c, d) if t < d / 2 return inBounce(t * 2, 0, c, d) * 0.5 + b else return outBounce(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b end end
defoutInBounce(t, b, c, d) if t < d / 2 return outBounce(t * 2, b, c / 2, d) else return inBounce((t * 2) - d, b + c / 2, c / 2, d) end end end end