Class: Ray::Animation::ColorVariation
- Inherits:
-
Ray::Animation
- Object
- Ray::Animation
- Ray::Animation::ColorVariation
- Defined in:
- lib/ray/animation/color_variation.rb
Overview
This animates the transition from a color to another one. Registered as #color_variation.
Instance Attribute Summary collapse
-
#attribute ⇒ Symbol
readonly
Attribut modified by the animation.
-
#current_value ⇒ Ray::Color
Current color.
-
#initial_value ⇒ Ray::Color
readonly
Initial color.
-
#variation ⇒ Array<Integer>
readonly
Variation between initial and last value.
Attributes inherited from Ray::Animation
Instance Method Summary collapse
-
#-@ ⇒ ColorVariation
Opposite color variation.
-
#last_value ⇒ Ray::Color
Last color.
- #pause_animation ⇒ Object
- #resume_animation ⇒ Object
- #setup(opts) ⇒ Object
- #setup_target ⇒ Object
- #update_target ⇒ Object
Methods inherited from Ray::Animation
#+, #-, #bounce!, #end_animation, #initialize, #loop!, #pause, #paused?, #progression, register_for, #resume, #running?, #start, #update
Methods included from Helper
#create_event_runner, #disable_event_group, effect_generator, #enable_event_group, #event_runner, #event_runner=, font, holding?, image, image_target, mouse_pos, music, #remove_event_group, #rotation, #scale_variation, sound, sound_buffer, sprite, text, #translation
Methods included from Matchers
Methods included from DSL::EventListener
#add_hook, #current_event_group, #current_event_group=, #event_group, #listener_runner, #listener_runner=, #on
Methods included from DSL::EventRaiser
#raise_event, #raiser_runner, #raiser_runner=
Constructor Details
This class inherits a constructor from Ray::Animation
Instance Attribute Details
#attribute ⇒ Symbol (readonly)
Returns Attribut modified by the animation.
88 89 90 |
# File 'lib/ray/animation/color_variation.rb', line 88 def attribute @attribute end |
#current_value ⇒ Ray::Color
Returns Current color.
79 80 81 |
# File 'lib/ray/animation/color_variation.rb', line 79 def current_value @current_value end |
#initial_value ⇒ Ray::Color (readonly)
Returns Initial color.
82 83 84 |
# File 'lib/ray/animation/color_variation.rb', line 82 def initial_value @initial_value end |
#variation ⇒ Array<Integer> (readonly)
Returns Variation between initial and last value.
85 86 87 |
# File 'lib/ray/animation/color_variation.rb', line 85 def variation @variation end |
Instance Method Details
#-@ ⇒ ColorVariation
Returns Opposite color variation.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ray/animation/color_variation.rb', line 67 def -@ if @initial_value color_variation(:from => last_value, :to => @initial_value, :attribute => @attribute, :duration => duration) else rev_variation = @variation.map { |o| -o } color_variation(:of => rev_variation, :attribute => @attribute, :duration => duration) end end |
#last_value ⇒ Ray::Color
Returns Last color.
91 92 93 94 95 96 97 98 99 |
# File 'lib/ray/animation/color_variation.rb', line 91 def last_value if @initial_value initial_array = @initial_value.to_a Ray::Color.new(*initial_array.each_with_index.map { |o, i| o + @variation[i] }) end end |
#pause_animation ⇒ Object
53 54 55 |
# File 'lib/ray/animation/color_variation.rb', line 53 def pause_animation @animations.each { |anim| anim.pause } end |
#resume_animation ⇒ Object
57 58 59 |
# File 'lib/ray/animation/color_variation.rb', line 57 def resume_animation @animations.each { |anim| anim.resume } end |
#setup(opts) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ray/animation/color_variation.rb', line 14 def setup(opts) if opts[:of] @current_value = @initial_value = nil @variation = opts[:of].to_a else @initial_value = opts[:from].to_color value_array = @initial_value.to_a @variation = opts[:to].to_a.each_with_index.map do |o, i| o - value_array[i] end end @attribute = opts[:attribute] || :color self.duration = opts[:duration] end |
#setup_target ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ray/animation/color_variation.rb', line 33 def setup_target unless @initial_value @current_value = target.send(@attribute) else @current_value = @initial_value.dup end @animations = [] @animations << float_variation(:of => @variation[0], :attribute => :r, :duration => duration) @animations << float_variation(:of => @variation[1], :attribute => :g, :duration => duration) @animations << float_variation(:of => @variation[2], :attribute => :b, :duration => duration) @animations << float_variation(:of => @variation[3], :attribute => :a, :duration => duration) @animations.each { |anim| anim.start(@current_value) } end |
#update_target ⇒ Object
61 62 63 64 |
# File 'lib/ray/animation/color_variation.rb', line 61 def update_target @animations.each { |anim| anim.update } target.send("#{@attribute}=", @current_value) end |