Class: Rustle::Transition
- Inherits:
-
Object
- Object
- Rustle::Transition
- Defined in:
- lib/rustle/transition.rb
Overview
Transitions
Transitions are created by subclassing this class. See FadeToTransition for the most basic example.
Creating a Transition
You’ll need to create a subclass of Transition and require it in your project.
Override the subclass’s #setup and #animate methods.
Use setup
to create any instance variables you may need to calculate before the transitio renders. The opts
passed in when calling Strip#transition are preserved and sent to this method.
#animate is called once-per-LED-per-frame, and expects you to return a object.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
Instance Method Summary collapse
-
#animate(led_index, starting_color, frame_num) ⇒ Color
Gets called once-per-LED-per-frame.
-
#initialize(strip, duration, opts = {}) ⇒ Transition
constructor
A new instance of Transition.
-
#setup(opts) ⇒ Object
Gets called before the transition begins.
Constructor Details
#initialize(strip, duration, opts = {}) ⇒ Transition
Returns a new instance of Transition.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rustle/transition.rb', line 21 def initialize(strip, duration, opts = {}) @strip = strip @duration = duration @total_frames = (duration.to_f / (1000/Rustle::FRAME_RATE.to_f)).ceil @frame_duration = 1.0/Rustle::FRAME_RATE self.setup(opts) render end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
19 20 21 |
# File 'lib/rustle/transition.rb', line 19 def duration @duration end |
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
19 20 21 |
# File 'lib/rustle/transition.rb', line 19 def frames @frames end |
Instance Method Details
#animate(led_index, starting_color, frame_num) ⇒ Color
Gets called once-per-LED-per-frame. Override it, and do your calculations therein. You will have access to any instance variables you declare in #setup.
Within this method, you also have the following available:
-
@total_frames: the total number of frames in the animation
-
@duration: the duration of the animation in milliseconds
-
@frame_duration: the duration of an individual frame (generally only used internally)
62 |
# File 'lib/rustle/transition.rb', line 62 def animate(led_index, starting_color, frame_num); end |
#setup(opts) ⇒ Object
Gets called before the transition begins. Override it to set up any instance variables you need in the #animate method.
Within this method, you also have the following available:
-
@total_frames: the total number of frames in the animation
-
@duration: the duration of the animation in milliseconds
-
@frame_duration: the duration of an individual frame (generally only used internally)
43 |
# File 'lib/rustle/transition.rb', line 43 def setup(opts); end |