class CyberarmEngine::Animator

Public Class Methods

new(start_time:, duration:, from:, to:, tween: :linear, &block) click to toggle source
# File lib/cyberarm_engine/animator.rb, line 3
def initialize(start_time:, duration:, from:, to:, tween: :linear, &block)
  @start_time = start_time
  @duration = duration
  @from = from.dup
  @to = to.dup
  @tween = tween
  @block = block
end

Public Instance Methods

color_hsv_transition(from = @from, to = @to, tween = @tween) click to toggle source
# File lib/cyberarm_engine/animator.rb, line 37
def color_hsv_transition(from = @from, to = @to, tween = @tween)
  hue = transition(from.hue, to.hue, tween)
  saturation = transition(from.saturation, to.saturation, tween)
  value = transition(from.value, to.value, tween)
  alpha = transition(from.alpha, to.alpha, tween)

  Gosu::Color.from_ahsv(alpha, hue, saturation, value)
end
color_transition(from = @from, to = @to, _tween = @tween) click to toggle source
# File lib/cyberarm_engine/animator.rb, line 28
def color_transition(from = @from, to = @to, _tween = @tween)
  r = transition(from.red, to.red)
  g = transition(from.green, to.green)
  b = transition(from.blue, to.blue)
  a = transition(from.alpha, to.alpha)

  Gosu::Color.rgba(r, g, b, a)
end
complete?() click to toggle source
# File lib/cyberarm_engine/animator.rb, line 20
def complete?
  progress >= 1.0
end
progress() click to toggle source
# File lib/cyberarm_engine/animator.rb, line 16
def progress
  ((Gosu.milliseconds - @start_time) / @duration.to_f).clamp(0.0, 1.0)
end
transition(from = @from, to = @to, tween = @tween) click to toggle source
# File lib/cyberarm_engine/animator.rb, line 24
def transition(from = @from, to = @to, tween = @tween)
  from + (to - from) * send("tween_#{tween}", progress)
end
tween_ease_in_out(t) click to toggle source
# File lib/cyberarm_engine/animator.rb, line 52
def tween_ease_in_out(t)
  (-0.5 * (Math.cos(Math::PI * t) - 1))
end
tween_linear(t) click to toggle source

NOTE: Use this for future reference? github.com/danro/easing-js/blob/master/easing.js

# File lib/cyberarm_engine/animator.rb, line 48
def tween_linear(t)
  t
end
update() click to toggle source
# File lib/cyberarm_engine/animator.rb, line 12
def update
  @block.call(self, @from, @to) if @block
end