Class: Tween

Inherits:
Object
  • Object
show all
Defined in:
lib/tween.rb

Overview

This is mostly an implementation of Robert Penner’s easing equations More information on the equations can be found here:

http://www.robertpenner.com/easing/

UziMonkey <[email protected]>

Defined Under Namespace

Modules: Back, Bounce, Circ, Cubic, Elastic, Expo, Linear, Quad, Quart, Quint, Sine

Constant Summary collapse

EASERS =

This is mostly for use by demo.rb

[
  Linear,
  
  Sine::In,
  Sine::Out,
  Sine::InOut,
  
  Circ::In,
  Circ::Out,
  Circ::InOut,
  
  Bounce::Out,
  Bounce::In,
  Bounce::InOut,
  
  Back::In,
  Back::Out,
  Back::InOut,
  
  Cubic::In,
  Cubic::Out,
  Cubic::InOut,
  
  Expo::In,
  Expo::Out,
  Expo::InOut,
  
  Quad::In,
  Quad::Out,
  Quad::InOut,
  
  Quart::In,
  Quart::Out,
  Quart::InOut,
  
  Quint::In,
  Quint::Out,
  Quint::InOut,
  
  Elastic::In,
  Elastic::Out
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, finish, easer, duration) ⇒ Tween

Returns a new instance of Tween.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tween.rb', line 14

def initialize(start, finish, easer, duration)
  @start, @finish = start, finish
  @easer, @duration = easer, duration
  
  unless @start.is_a? Enumerable
    @start = [@start]
  end

  unless @finish.is_a? Enumerable
    @finish = [@finish]
  end

  @time = 0
  @done = false
end

Instance Attribute Details

#doneObject (readonly)

Returns the value of attribute done.



11
12
13
# File 'lib/tween.rb', line 11

def done
  @done
end

#easerObject (readonly)

Returns the value of attribute easer.



12
13
14
# File 'lib/tween.rb', line 12

def easer
  @easer
end

Instance Method Details

#[](idx) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/tween.rb', line 38

def [](idx)
  @easer.ease(
    @time,
    @start[idx],
    (@finish[idx] - @start[idx]),
    @duration
  )
end

#update(delta) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/tween.rb', line 30

def update(delta)
  @time += delta
  if @time > @duration
    @time = @duration
    @done = true
  end
end

#valueObject



47
# File 'lib/tween.rb', line 47

def value; self[0]; end

#xObject



48
# File 'lib/tween.rb', line 48

def x; self[0]; end

#yObject



49
# File 'lib/tween.rb', line 49

def y; self[1]; end

#zObject



50
# File 'lib/tween.rb', line 50

def z; self[2]; end