Method: Selenium::WebDriver::Support::Color.from_hsl

Defined in:
lib/selenium/webdriver/support/color.rb

.from_hsl(h, s, l, a) ⇒ Object

rubocop:disable Naming/MethodParameterName


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/selenium/webdriver/support/color.rb', line 75

def self.from_hsl(h, s, l, a) # rubocop:disable Naming/MethodParameterName
  h = Float(h) / 360
  s = Float(s) / 100
  l = Float(l) / 100
  a = Float(a || 1)

  if s.zero?
    r = l
    g = r
    b = r
  else
    luminocity2 = l < 0.5 ? l * (s + 1) : l + s - (l * s)
    luminocity1 = (l * 2) - luminocity2

    r = hue_to_rgb(luminocity1, luminocity2, h + (1.0 / 3.0))
    g = hue_to_rgb(luminocity1, luminocity2, h)
    b = hue_to_rgb(luminocity1, luminocity2, h - (1.0 / 3.0))
  end

  new (r * 255).round, (g * 255).round, (b * 255).round, a
end