Class: LifxToys::Rainbow
- Inherits:
-
Object
- Object
- LifxToys::Rainbow
- Defined in:
- lib/lifx_toys/rainbow.rb
Constant Summary collapse
- CYCLE_TIME =
1
Instance Method Summary collapse
- #color_for_light(base_color, index) ⇒ Object
-
#initialize ⇒ Rainbow
constructor
A new instance of Rainbow.
- #light_count ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Rainbow
Returns a new instance of Rainbow.
7 8 9 10 |
# File 'lib/lifx_toys/rainbow.rb', line 7 def initialize @lights = LifxHttp::LifxLight.get_lights.select{|x| x.connected } puts "Running with #{light_count} lights..." end |
Instance Method Details
#color_for_light(base_color, index) ⇒ Object
28 29 30 31 |
# File 'lib/lifx_toys/rainbow.rb', line 28 def color_for_light(base_color, index) offset = (360/light_count) * index "hue:#{((base_color) + offset) % 360}" end |
#light_count ⇒ Object
12 13 14 |
# File 'lib/lifx_toys/rainbow.rb', line 12 def light_count @lights.count end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lifx_toys/rainbow.rb', line 16 def run @lights.each{|x| x.set_color("saturation:1 brightness:1", duration: 0)} while (true) (0...36).each do |color| @lights.each_with_index do |light, light_number| light.set_color(color_for_light(color * 10, light_number), duration: CYCLE_TIME) end sleep(CYCLE_TIME) end end end |