Class: TEF::Animation::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/tef/Animation/Color.rb

Constant Summary collapse

PARAM_TYPES =
[:jump, :velocity, :target, :delay_a, :delay_b]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_num) ⇒ Color

Initialize a new color.

Parameters:

  • value_num (Integer)

    The hardware ID of this Color. must match the ID defined in the animation slaves.



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_aObject

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_bObject

Smoothing delay for color transition. If both #delay_a and delay_b are nonzero, setting #target will cause a smooth transition of the output color.

delay_b defines the transition speed of #target to an internal, non-visible ‘velocity’ color.



# File 'lib/tef/Animation/Color.rb', line 51

#IDInteger (readonly)

Returns Hardware-Number of this Color.

Returns:

  • (Integer)

    Hardware-Number of this Color



19
20
21
# File 'lib/tef/Animation/Color.rb', line 19

def ID
  @ID
end

#jumpNumeric

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

Returns:

  • (Numeric)

    Current RGB color code.



# File 'lib/tef/Animation/Color.rb', line 25

#module_idString?

Returns Module-ID of the Animatable that this color belongs to.

Returns:

  • (String, nil)

    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

#targetObject

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

#velocityNumeric

Set the animation buffer to the given color. Has no effect unless #delay_b was configued, in which case the animation will temporarily fade to velocity, then fade back to #target

Returns:

  • (Numeric)

    Current RGB color code.



# File 'lib/tef/Animation/Color.rb', line 31

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.

Examples:

a_color.configure({ delay_a: 10, target: 0xFF0000 })


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.

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


132
133
134
# File 'lib/tef/Animation/Color.rb', line 132

def has_changes?
	return !@changes.empty?
end

#set_stringObject

Note:

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_idString

Returns Total ID of this Color, in the form ‘SxxMxxVxx’.

Returns:

  • (String)

    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