Class: NanoleafRuby::ColorUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoleaf_ruby/color_utils.rb

Class Method Summary collapse

Class Method Details

.get_color(value) ⇒ Object



5
6
7
8
9
10
# File 'lib/nanoleaf_ruby/color_utils.rb', line 5

def self.get_color(value)
  color = Chroma.paint(value).to_hsv
  magic_regex = /hsv\((?<hue>\d+),\s(?<sat>\d+)%,\s(?<bright>\d+)%\)/i
  values = magic_regex.match(color)
  [values[:hue].to_i, values[:sat].to_i, values[:bright].to_i]
end

.hsv_to_rgb(hue, sat, val) ⇒ Object



12
13
14
15
# File 'lib/nanoleaf_ruby/color_utils.rb', line 12

def self.hsv_to_rgb(hue, sat, val)
  color = Chroma.paint("hsv(#{hue}, #{sat}%, #{val}%)")
  color.to_rgb
end