Class: ColorMath::HSL

Inherits:
Object
  • Object
show all
Includes:
Color
Defined in:
lib/colormath/color/hsl.rb

Overview

A colour represented and stored as hue, saturation and luminance components

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Color

#compact_hex, #hex, #inspect

Constructor Details

#initialize(h, s, l) ⇒ HSL

Initialize an HSL colour where:

0 <= h <= 360
0 <= s <=   1
0 <= l <=   1

Saturation and luminance values outside these ranges will be clipped. Hue values will be mapped to a circle, so that e.g. -20 becomes 340.



18
19
20
21
22
# File 'lib/colormath/color/hsl.rb', line 18

def initialize(h, s, l)
  @hue        = h % 360
  @saturation = force_range(s, 0,   1).to_f
  @luminance  = force_range(l, 0,   1).to_f
end

Instance Attribute Details

#alphaObject (readonly)

Returns the value of attribute alpha.



8
9
10
# File 'lib/colormath/color/hsl.rb', line 8

def alpha
  @alpha
end

#hueObject (readonly)

Returns the value of attribute hue.



8
9
10
# File 'lib/colormath/color/hsl.rb', line 8

def hue
  @hue
end

#luminanceObject (readonly)

Returns the value of attribute luminance.



8
9
10
# File 'lib/colormath/color/hsl.rb', line 8

def luminance
  @luminance
end

#saturationObject (readonly)

Returns the value of attribute saturation.



8
9
10
# File 'lib/colormath/color/hsl.rb', line 8

def saturation
  @saturation
end

Instance Method Details

#blueObject

The blue component of the colour in RGB representation where 0 <= b <= 1



38
39
40
# File 'lib/colormath/color/hsl.rb', line 38

def blue
  t = component(hk - (1/3.0))
end

#greenObject

The green component of the colour in RGB representation where 0 <= g <= 1



32
33
34
# File 'lib/colormath/color/hsl.rb', line 32

def green
  t = component(hk)
end

#redObject

The red component of the colour in RGB representation where 0 <= r <= 1



26
27
28
# File 'lib/colormath/color/hsl.rb', line 26

def red
  t = component(hk + (1/3.0))
end