Class: Abachrome::ColorModels::Oklch
- Inherits:
-
Object
- Object
- Abachrome::ColorModels::Oklch
- Defined in:
- lib/abachrome/color_models/oklch.rb
Class Method Summary collapse
-
.from_oklab(l, a, b) ⇒ Array<Numeric>
Converts OKLab color coordinates to OKLCH color coordinates.
-
.normalize(l, c, h) ⇒ Array<AbcDecimal>
Normalizes OKLCH color values to their standard ranges.
-
.to_oklab(l, c, h) ⇒ Array<Numeric>
Converts OKLCH color coordinates to OKLab color coordinates.
Class Method Details
.from_oklab(l, a, b) ⇒ Array<Numeric>
Converts OKLab color coordinates to OKLCH color coordinates.
-
l is the lightness component (unchanged from OKLab)
-
c is the chroma component (calculated from a and b)
-
h is the hue angle in degrees (0-360)
70 71 72 73 74 75 76 |
# File 'lib/abachrome/color_models/oklch.rb', line 70 def self.from_oklab(l, a, b) # Convert OKLab to OKLCH c = Math.sqrt((a * a) + (b * b)) h = Math.atan2(b, a) * 180 / Math::PI h += 360 if h.negative? [l, c, h] end |
.normalize(l, c, h) ⇒ Array<AbcDecimal>
Normalizes OKLCH color values to their standard ranges.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/abachrome/color_models/oklch.rb', line 31 def self.normalize(l, c, h) l = AbcDecimal(l) c = AbcDecimal(c) h = AbcDecimal(h) # Normalize hue to 0-360 range h -= 360 while h >= 360 h += 360 while h.negative? # Normalize lightness and chroma to 0-1 range l = l.clamp(0, 1) c = c.clamp(0, 1) [l, c, h] end |
.to_oklab(l, c, h) ⇒ Array<Numeric>
Converts OKLCH color coordinates to OKLab color coordinates.
53 54 55 56 57 58 59 |
# File 'lib/abachrome/color_models/oklch.rb', line 53 def self.to_oklab(l, c, h) # Convert OKLCH to OKLab h_rad = h * Math::PI / 180 a = c * Math.cos(h_rad) b = c * Math.sin(h_rad) [l, a, b] end |