Module: Moon::Easing::ElasticInOut

Defined in:
lib/moon/packages/std/animation/easing.rb

Class Method Summary collapse

Class Method Details

.call(k) ⇒ Object


206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/moon/packages/std/animation/easing.rb', line 206

def self.call(k)
  s = nil
  a = 0.1
  p = 0.4
  if k == 0
    0
  elsif k == 1
    1
  end

  if a == 0 || a < 1
    a = 1
    s = p / 4
  else
    s = p * Math.asin(1 / a) / (2 * Math::PI)
  end
  if (k *= 2) < 1
    -0.5 * (a * (2 ** (10 * (k -= 1))) * Math.sin((k - s) * (2 * Math::PI) / p))
  else
    a * (2 ** (-10 * (k -= 1))) * Math.sin((k - s) * (2 * Math::PI) / p) * 0.5 + 1
  end
end