Class: LifxToys::Colors

Inherits:
Object
  • Object
show all
Defined in:
lib/lifx_toys/colors.rb

Constant Summary collapse

HUE_RANGE =
0..360
BRIGHTNESS_RANGE =
20..80
SATURATION_RANGE =
20..100
CYCLE_TIME =
10.0

Instance Method Summary collapse

Constructor Details

#initializeColors

Returns a new instance of Colors.



12
13
14
# File 'lib/lifx_toys/colors.rb', line 12

def initialize
  @lights = LifxHttp::LifxLight.get_lights.select{|x| x.connected }
end

Instance Method Details

#random_brightnessObject



33
34
35
# File 'lib/lifx_toys/colors.rb', line 33

def random_brightness
  rand(BRIGHTNESS_RANGE).to_f / 100
end

#random_hueObject



25
26
27
# File 'lib/lifx_toys/colors.rb', line 25

def random_hue
  rand(HUE_RANGE)
end

#random_saturationObject



29
30
31
# File 'lib/lifx_toys/colors.rb', line 29

def random_saturation
  rand(SATURATION_RANGE).to_f / 100
end

#runObject



16
17
18
19
20
21
22
23
# File 'lib/lifx_toys/colors.rb', line 16

def run
  while (true)
    @lights.each do |light|
      light.set_color("hue:#{random_hue} saturation:#{random_saturation} brightness:#{random_brightness}", duration: CYCLE_TIME* 1.5)
      sleep(CYCLE_TIME/ @lights.count)
    end
  end
end