Class: Castaway::Animation
- Inherits:
-
Object
- Object
- Castaway::Animation
- Defined in:
- lib/castaway/animation.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Class Method Summary collapse
Instance Method Summary collapse
- #[](t) ⇒ Object
-
#initialize(interpolator, from, to) ⇒ Animation
constructor
A new instance of Animation.
Constructor Details
#initialize(interpolator, from, to) ⇒ Animation
Returns a new instance of Animation.
23 24 25 26 27 28 |
# File 'lib/castaway/animation.rb', line 23 def initialize(interpolator, from, to) @interpolator = interpolator @from = from.to_f @to = to.to_f @duration = @to - @from end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/castaway/animation.rb', line 6 def duration @duration end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
6 7 8 |
# File 'lib/castaway/animation.rb', line 6 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
6 7 8 |
# File 'lib/castaway/animation.rb', line 6 def to @to end |
Class Method Details
.from_options(options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/castaway/animation.rb', line 8 def self.() factory = Castaway::Interpolation.lookup() initial = [:initial] || 0.0 final = [:final] || (initial + 1.0) interpolator = factory.new(initial, final) from = [:from] || raise(ArgumentError, 'animations require `from` time') to = [:to] || ([:length] ? from + [:length] : nil) || raise(ArgumentError, 'animations require `to` or `length`') new(interpolator, from, to) end |
Instance Method Details
#[](t) ⇒ Object
30 31 32 33 34 |
# File 'lib/castaway/animation.rb', line 30 def [](t) # adjust t to 0..1 adjusted_t = duration.zero? ? 1.0 : (t - from) / duration.to_f @interpolator[adjusted_t] end |