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

Constant Summary

Constants included from Color

Color::EPSILON

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Color

#==, #hex, #inspect

Constructor Details

#initialize(h, s, l) ⇒ HSL

Initialize an HSL colour where:

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

Values outside these ranges will be clippped.



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

def initialize(h, s, l)
  @hue        = force_range(h, 0, 360).to_f
  @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



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

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

#greenObject

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



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

def green
  t = component(hk)
end

#redObject

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



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

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