Module: Husler

Extended by:
Husler
Included in:
Husler
Defined in:
lib/husler.rb,
lib/husler/version.rb,
lib/husler/constants.rb

Overview

:nodoc:

Constant Summary collapse

VERSION =
"0.1.0"
PI =
Math::PI
INFINITY =

PI = 3.1415926535897932384626433832795

+1.0/0
ONE_THIRD =

positive infinity technically

(1.0 / 3.0)
M =
[
  [3.2406, -1.5372, -0.4986],
  [-0.9689, 1.8758, 0.0415],
  [0.0557, -0.2040, 1.0570]
]
M_INV =
[
  [0.4124, 0.3576, 0.1805],
  [0.2126, 0.7152, 0.0722],
  [0.0193, 0.1192, 0.9505]
]
LIMITS =
[0.0, 1.0]
REF_X =
0.95047
REF_Y =
1.00000
REF_Z =
1.08883
REF_U =
0.19784
REF_V =
0.46834
LAB_E =
0.008856
LAB_K =
903.3

Instance Method Summary collapse

Instance Method Details

#husl_to_rgb(h, s, l) ⇒ Object

Pass in HUSL values and get back RGB values, H ranges from 0 to 360, S and L from 0 to 100. RGB values will range from 0 to 1.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
# File 'lib/husler.rb', line 10

def husl_to_rgb(h, s, l)
  raise ArgumentError.new("h value (#{h}) must be in the range 0..360") unless (0..360).include? h
  raise ArgumentError.new("s value (#{s}) must be in the range 0..100") unless (0..100).include? s
  raise ArgumentError.new("l value (#{l}) must be in the range 0..100") unless (0..100).include? l

  xyz_rgb(luv_xyz(lch_luv(husl_lch([h, s, l]))))
end

#rgb_to_husl(r, g, b) ⇒ Object

Pass in RGB values ranging from 0 to 1 and get back HUSL values. H ranges from 0 to 360, S and L from 0 to 100.

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/husler.rb', line 20

def rgb_to_husl(r, g, b)
  rgb = [r, g, b]
  raise ArgumentError.new("rgb values (#{r}, #{g}, #{b}) must all be in the range 0..1") if rgb.any? { |v| !(0..1).include? v }
  lch_husl(luv_lch(xyz_luv(rgb_xyz(rgb))))
end