Class: Colors::HUSL

Inherits:
HSL show all
Defined in:
lib/colors/husl.rb

Overview

Human-friendly alternative to HSL color space. The definition of HUSL is provided in http://www.hsluv.org.

Instance Attribute Summary

Attributes inherited from HSL

#h, #l, #s

Instance Method Summary collapse

Methods inherited from HSL

#components, #initialize, #to_hsl, #to_hsla, #to_rgba

Methods inherited from AbstractColor

#inspect

Constructor Details

This class inherits a constructor from Colors::HSL

Instance Method Details

#==(other) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/colors/husl.rb', line 5

def ==(other)
  case other
  when HUSL
    h == other.h && s == other.s && l == other.l
  else
    other == self
  end
end

#desaturate(factor) ⇒ Object



14
15
16
# File 'lib/colors/husl.rb', line 14

def desaturate(factor)
  to_rgb.desaturate(factor).to_husl
end

#lch_componentsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/colors/husl.rb', line 35

def lch_components
  l = self.l * 100r
  s = self.s * 100r

  if l > 99.9999999 || l < 1e-8
    c = 0r
  else
    mx = Convert.max_chroma(l, h)
    c = mx / 100r * s
  end

  h = s < 1e-8 ? 0r : self.h

  [l, c, h]
end

#rgb_componentsObject



31
32
33
# File 'lib/colors/husl.rb', line 31

def rgb_components
  to_xyz.rgb_components
end

#to_huslObject



18
19
20
# File 'lib/colors/husl.rb', line 18

def to_husl
  self
end

#to_rgbObject



22
23
24
# File 'lib/colors/husl.rb', line 22

def to_rgb
  RGB.new(*rgb_components)
end

#to_xyzObject



26
27
28
29
# File 'lib/colors/husl.rb', line 26

def to_xyz
  x, y, z = Convert.lch_to_xyz(*lch_components)
  XYZ.new(x, y, z)
end