lib/cyberarm_engine/animator.rb in cyberarm_engine-0.18.0 vs lib/cyberarm_engine/animator.rb in cyberarm_engine-0.19.0
- old
+ new
@@ -41,16 +41,179 @@
alpha = transition(from.alpha, to.alpha, tween)
Gosu::Color.from_ahsv(alpha, hue, saturation, value)
end
- # NOTE: Use this for future reference? https://github.com/danro/easing-js/blob/master/easing.js
+ # Tween functions based on those provided here: https://github.com/danro/easing-js/blob/master/easing.js
+ # Under MIT / BSD
def tween_linear(t)
t
end
- def tween_ease_in_out(t)
+ def tween_ease_in_quad(t)
+ t ** 2
+ end
+
+ def tween_ease_out_quad(t)
+ -((t - 1) ** 2) -1
+ end
+
+ def tween_ease_in_out_quad(t)
+ return 0.5 * (t ** 2) if (t /= 0.5) < 1
+ return -0.5 * ((t -= 2) * t - 2)
+ end
+
+ def tween_ease_in_cubic(t)
+ t ** 3
+ end
+
+ def tween_ease_out_cubic(t)
+ ((t - 1) ** 3) + 1
+ end
+
+ def tween_ease_in_out_cubic(t)
+ return 0.5 * (t ** 3) if ((t /= 0.5) < 1)
+ return 0.5 * ((t - 2) ** 3) + 2
+ end
+
+ def tween_ease_in_quart(t)
+ t ** 4
+ end
+
+ def tween_ease_out_quart(t)
+ -((t - 1) ** 4) - 1
+ end
+
+ def tween_ease_in_out_quart(t)
+ return 0.5 * (t ** 4) if ((t /= 0.5) < 1)
+ return -0.5 * ((t -= 2) * (t ** 3) - 2)
+ end
+
+ def tween_ease_in_quint(t)
+ t ** 5
+ end
+
+ def tween_ease_out_quint(t)
+ ((t - 1) ** 5) + 1
+ end
+
+ def tween_ease_in_out_quint(t)
+ return 0.5 * (t ** 5) if ((t /= 0.5) < 1)
+ return 0.5 * ((t - 2) ** 5) + 2
+ end
+
+ def tween_ease_in(t) # sine
+ -Math.cos(t * (Math::PI / 2)) + 1
+ end
+
+ def tween_ease_out(t) # sine
+ Math.sin(t * (Math::PI / 2))
+ end
+
+ def tween_ease_in_out(t) # sine
(-0.5 * (Math.cos(Math::PI * t) - 1))
+ end
+
+ def tween_ease_in_expo(t)
+ (t == 0) ? 0 : 2 ** 10 * (t - 1)
+ end
+
+ def tween_ease_out_expo(t)
+ (t == 1) ? 1 : -(2 ** -10 * t) + 1
+ end
+
+ def tween_ease_in_out_expo(t)
+ return 0 if (t == 0)
+ return 1 if (t == 1)
+ return 0.5 * (2 ** 10 * (t - 1)) if ((t /= 0.5) < 1)
+ return 0.5 * (-(2 ** -10 * (t -= 1)) + 2)
+ end
+
+ def tween_ease_in_circ(t)
+ -(Math.sqrt(1 - (t * t)) - 1)
+ end
+
+ def tween_ease_out_circ(t)
+ Math.sqrt(1 - ((t - 1) ** 2))
+ end
+
+ def tween_ease_in_out_circ(t)
+ return -0.5 * (Math.sqrt(1 - t * t) - 1) if ((t /= 0.5) < 1)
+ return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1)
+ end
+
+ def tween_ease_in_back(t)
+ s = 1.70158
+ t * t * ((s + 1) * t - s)
+ end
+
+ def tween_ease_out_back(t)
+ s = 1.70158
+ (t = t - 1) * t * ((s + 1) * t + s) + 1
+ end
+
+ def tween_ease_in_out_back(t)
+ s = 1.70158
+ return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) if ((t /= 0.5) < 1)
+ return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2)
+ end
+
+ def tween_elastic(t)
+ -1 * (4 ** (-8 * t)) * Math.sin((t * 6 - 1) * (2 * Math::PI) / 2) + 1
+ end
+
+ def tween_swing_from_to(t)
+ s = 1.70158
+ return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)) if (t /= 0.5) < 1
+ return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2)
+ end
+
+ def tween_swing_from(t)
+ s = 1.70158;
+ t * t * ((s + 1) * t - s)
+ end
+
+ def tween_swing_to(t)
+ s = 1.70158
+ (t -= 1) * t * ((s + 1) * t + s) + 1
+ end
+
+ def tween_bounce(t)
+ if (t < (1 / 2.75))
+ (7.5625 * t * t)
+ elsif (t < (2 / 2.75))
+ (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)
+ elsif (t < (2.5 / 2.75))
+ (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)
+ else
+ (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)
+ end
+ end
+
+ def tween_bounce_past(t)
+ if (t < (1 / 2.75))
+ # missing "2 -"?
+ (7.5625 * t * t)
+ elsif (t < (2 / 2.75))
+ 2 - (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75)
+ elsif (t < (2.5 / 2.75))
+ 2 - (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375)
+ else
+ 2 - (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375)
+ end
+ end
+
+ def tween_ease_from_to(t)
+ return 0.5 * (t ** 4) if ((t /= 0.5) < 1)
+ return -0.5 * ((t -= 2) * (t ** 3) - 2)
+ end
+
+ def tween_ease_from(t)
+ t ** 4
+ end
+
+ def tween_ease_to(t)
+ t ** 0.25
end
end
end