Class: Tween
- Inherits:
-
Object
- Object
- Tween
- 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
-
#done ⇒ Object
readonly
Returns the value of attribute done.
-
#easer ⇒ Object
readonly
Returns the value of attribute easer.
Instance Method Summary collapse
- #[](idx) ⇒ Object
-
#initialize(start, finish, easer, duration) ⇒ Tween
constructor
A new instance of Tween.
- #update(delta) ⇒ Object
- #value ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
- #z ⇒ Object
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
#done ⇒ Object (readonly)
Returns the value of attribute done.
11 12 13 |
# File 'lib/tween.rb', line 11 def done @done end |
#easer ⇒ Object (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 |
#value ⇒ Object
47 |
# File 'lib/tween.rb', line 47 def value; self[0]; end |
#x ⇒ Object
48 |
# File 'lib/tween.rb', line 48 def x; self[0]; end |
#y ⇒ Object
49 |
# File 'lib/tween.rb', line 49 def y; self[1]; end |
#z ⇒ Object
50 |
# File 'lib/tween.rb', line 50 def z; self[2]; end |