Class: TEF::Animation::Color
- Inherits:
-
Object
- Object
- TEF::Animation::Color
- Defined in:
- lib/tef/Animation/Color.rb
Constant Summary collapse
- PARAM_TYPES =
[:jump, :velocity, :target, :delay_a, :delay_b]
Instance Attribute Summary collapse
-
#delay_a ⇒ Object
Smoothing delay for color transition.
-
#delay_b ⇒ Object
Smoothing delay for color transition.
-
#ID ⇒ Integer
readonly
Hardware-Number of this Color.
-
#jump ⇒ Numeric
Immediately set the color of this Color to the jump value, skipping animation.
-
#module_id ⇒ String?
Module-ID of the Animatable that this color belongs to.
-
#target ⇒ Object
Target of the color animation.
-
#velocity ⇒ Numeric
Set the animation buffer to the given color.
Instance Method Summary collapse
-
#configure(data) ⇒ Object
Configure the color with a hash.
-
#generic_set(key, value) ⇒ Object
Internal function to set any of the Color’s parameters.
- #has_changes? ⇒ Boolean
-
#initialize(value_num) ⇒ Color
constructor
Initialize a new color.
-
#set_string ⇒ Object
Internal function to retrieve the list of changes for this color.
-
#total_id ⇒ String
Total ID of this Color, in the form ‘SxxMxxVxx’.
Constructor Details
#initialize(value_num) ⇒ Color
Initialize a new color.
62 63 64 65 66 67 68 69 |
# File 'lib/tef/Animation/Color.rb', line 62 def initialize(value_num) @ID = value_num; @current = Hash.new(0); @changes = {} @is_animated = false; end |
Instance Attribute Details
#delay_a ⇒ Object
Smoothing delay for color transition. If #delay_b is zero and delay_a is nonzero, setting #target will cause the actual color to slowly transition to #target. Larger values cause faster transitions!
If delay_b is set, delay_a defines the smoothing speed between the ‘velocity’ color and the actual color.
|
# File 'lib/tef/Animation/Color.rb', line 42
|
#delay_b ⇒ Object
|
# File 'lib/tef/Animation/Color.rb', line 51
|
#ID ⇒ Integer (readonly)
Returns Hardware-Number of this Color.
19 20 21 |
# File 'lib/tef/Animation/Color.rb', line 19 def ID @ID end |
#jump ⇒ Numeric
Immediately set the color of this Color to the jump value, skipping animation. If animation is set, the Color will then fade back to the value defined by #target
|
# File 'lib/tef/Animation/Color.rb', line 25
|
#module_id ⇒ String?
Returns Module-ID of the Animatable that this color belongs to.
23 24 25 |
# File 'lib/tef/Animation/Color.rb', line 23 def module_id @module_id end |
#target ⇒ Object
Target of the color animation. Set this as hexadecimal RGB color code, i.e. 0xRRGGBB, with an optional alpha channel (i.e. 0xFF000000) for a fully transparent black.
|
# File 'lib/tef/Animation/Color.rb', line 37
|
Instance Method Details
#configure(data) ⇒ Object
Configure the color with a hash.
This lets the user configure the color by passing a hash. The data will be passed into the five attributes of this color according to their key.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/tef/Animation/Color.rb', line 120 def configure(data) if data.is_a? Numeric self.target = data elsif data.is_a? Hash data.each do |key, value| generic_set key, value end else raise ArgumentError, 'Config data must be Hash or Numeric' end end |
#generic_set(key, value) ⇒ Object
Internal function to set any of the Color’s parameters.
This can be called by the user, but it is preferrable to use #configure or the matching parameter setter functions.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/tef/Animation/Color.rb', line 89 def generic_set(key, value) raise ArgumentError, 'Key does not exist!' unless PARAM_TYPES.include? key raise ArgumentError, "Input must be numeric!" unless value.is_a? Numeric return if ![:jump, :velocity].include?(key) && value == @current[key] if [:delay_a, :delay_b].include? key @is_animated = true end @current[key] = value @changes[key] = true end |
#has_changes? ⇒ Boolean
132 133 134 |
# File 'lib/tef/Animation/Color.rb', line 132 def has_changes? return !@changes.empty? end |
#set_string ⇒ Object
Do not call this as user unless you know what you are doing! This will delete the retrieved changes, which may cause loss of data if they are not properly sent to the animation slaves!
Internal function to retrieve the list of changes for this color.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/tef/Animation/Color.rb', line 146 def set_string() return nil unless has_changes? if !@is_animated return nil unless @changes[:target] out_str = "V#{@ID} J#{@current[:target].to_s(16)};" @changes = {} return out_str end out_str = ["V#{@ID}"]; out_str << "J#{@current[:jump].to_s(16)}" if @changes[:jump] out_str << "V#{@current[:velocity].to_s(16)}" if @changes[:velocity] config_strs = []; config_strs_out = []; [:target, :delay_a, :delay_b].each do |k| if k == :target config_strs << @current[k].to_s(16) else config_strs << rcut(@current[k]) end config_strs_out = config_strs.dup if @changes[k] end @changes = {} (out_str + config_strs_out).join(' ') + ';' end |
#total_id ⇒ String
Returns Total ID of this Color, in the form ‘SxxMxxVxx’.
81 82 83 |
# File 'lib/tef/Animation/Color.rb', line 81 def total_id() "#{@module_id}V#{@ID}" end |