Module: AnimateIt::AnimationHelpers
- Included in:
- Scene
- Defined in:
- lib/animate_it/animation_helpers.rb
Instance Method Summary collapse
- #act_local(beat_name) ⇒ Object
- #animation_vars(**properties) ⇒ Object
- #at_act(beat_name, ranges, values, easing: :ease_out) ⇒ Object
- #at_global(ranges, values, easing: :ease_out) ⇒ Object
- #beat_end(beat_name) ⇒ Object
- #beat_frame(beat_name) ⇒ Object
- #beat_range(beat_name) ⇒ Object
- #fade(start_frame, end_frame, from: 0, to: 1, easing: :ease_out) ⇒ Object
- #freeze_frame(frozen_frame, active: true) ⇒ Object
- #interpolate_range(input_range, output_range, easing: :ease_out) ⇒ Object
- #loop_frame(duration, frame: local_frame) ⇒ Object
- #loop_iteration(duration, frame: local_frame) ⇒ Object
- #press(start_frame, middle_frame, end_frame, from: 1.0, to: 1.08, easing: :ease_out) ⇒ Object
- #pulse(start_frame, middle_frame, end_frame, from:, to:, back_to: from, easing: :ease_out) ⇒ Object
- #slide(start_frame, end_frame, from: 16, to: 0, easing: :ease_out) ⇒ Object
Instance Method Details
#act_local(beat_name) ⇒ Object
46 47 48 |
# File 'lib/animate_it/animation_helpers.rb', line 46 def act_local(beat_name) local_frame - composition_class.beats.fetch(beat_name).start_frame end |
#animation_vars(**properties) ⇒ Object
3 4 5 |
# File 'lib/animate_it/animation_helpers.rb', line 3 def animation_vars(**properties) Style.vars(**properties) end |
#at_act(beat_name, ranges, values, easing: :ease_out) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/animate_it/animation_helpers.rb', line 50 def at_act(beat_name, ranges, values, easing: :ease_out) interpolate( act_local(beat_name), ranges, values, easing:, extrapolate_left: :clamp, extrapolate_right: :clamp ).round(4) end |
#at_global(ranges, values, easing: :ease_out) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/animate_it/animation_helpers.rb', line 61 def at_global(ranges, values, easing: :ease_out) interpolate( local_frame, ranges, values, easing:, extrapolate_left: :clamp, extrapolate_right: :clamp ).round(4) end |
#beat_end(beat_name) ⇒ Object
76 77 78 79 |
# File 'lib/animate_it/animation_helpers.rb', line 76 def beat_end(beat_name) beat = composition_class.beats.fetch(beat_name) beat.start_frame + beat.duration_frames end |
#beat_frame(beat_name) ⇒ Object
72 73 74 |
# File 'lib/animate_it/animation_helpers.rb', line 72 def beat_frame(beat_name) composition_class.beats.fetch(beat_name).start_frame end |
#beat_range(beat_name) ⇒ Object
81 82 83 84 |
# File 'lib/animate_it/animation_helpers.rb', line 81 def beat_range(beat_name) beat = composition_class.beats.fetch(beat_name) [beat.start_frame, beat.start_frame + beat.duration_frames] end |
#fade(start_frame, end_frame, from: 0, to: 1, easing: :ease_out) ⇒ Object
7 8 9 |
# File 'lib/animate_it/animation_helpers.rb', line 7 def fade(start_frame, end_frame, from: 0, to: 1, easing: :ease_out) interpolate_range([start_frame, end_frame], [from, to], easing:) end |
#freeze_frame(frozen_frame, active: true) ⇒ Object
42 43 44 |
# File 'lib/animate_it/animation_helpers.rb', line 42 def freeze_frame(frozen_frame, active: true) active.respond_to?(:call) && !active.call(local_frame) ? local_frame : frozen_frame end |
#interpolate_range(input_range, output_range, easing: :ease_out) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/animate_it/animation_helpers.rb', line 23 def interpolate_range(input_range, output_range, easing: :ease_out) interpolate( local_frame, input_range, output_range, easing:, extrapolate_left: :clamp, extrapolate_right: :clamp ).round(4) end |
#loop_frame(duration, frame: local_frame) ⇒ Object
34 35 36 |
# File 'lib/animate_it/animation_helpers.rb', line 34 def loop_frame(duration, frame: local_frame) frame % AnimateIt::Units.frames(duration, fps:) end |
#loop_iteration(duration, frame: local_frame) ⇒ Object
38 39 40 |
# File 'lib/animate_it/animation_helpers.rb', line 38 def loop_iteration(duration, frame: local_frame) frame / AnimateIt::Units.frames(duration, fps:) end |
#press(start_frame, middle_frame, end_frame, from: 1.0, to: 1.08, easing: :ease_out) ⇒ Object
15 16 17 |
# File 'lib/animate_it/animation_helpers.rb', line 15 def press(start_frame, middle_frame, end_frame, from: 1.0, to: 1.08, easing: :ease_out) interpolate_range([start_frame, middle_frame, end_frame], [from, to, from], easing:) end |
#pulse(start_frame, middle_frame, end_frame, from:, to:, back_to: from, easing: :ease_out) ⇒ Object
19 20 21 |
# File 'lib/animate_it/animation_helpers.rb', line 19 def pulse(start_frame, middle_frame, end_frame, from:, to:, back_to: from, easing: :ease_out) interpolate_range([start_frame, middle_frame, end_frame], [from, to, back_to], easing:) end |
#slide(start_frame, end_frame, from: 16, to: 0, easing: :ease_out) ⇒ Object
11 12 13 |
# File 'lib/animate_it/animation_helpers.rb', line 11 def (start_frame, end_frame, from: 16, to: 0, easing: :ease_out) interpolate_range([start_frame, end_frame], [from, to], easing:) end |