Module: Abachrome::ColorMixins::ToOklch
- Defined in:
- lib/abachrome/color_mixins/to_oklch.rb
Instance Method Summary collapse
-
#chroma ⇒ AbcDecimal
Returns the chroma value of the color by converting it to the OKLCH color space.
-
#hue ⇒ AbcDecimal
Returns the hue value of the color in the OKLCH color space.
-
#lightness ⇒ AbcDecimal
Returns the lightness component of the color in the OKLCH color space.
-
#oklch_array ⇒ Array<Numeric>
Returns the OKLCH coordinates of the color as an array.
-
#oklch_values ⇒ Array<AbcDecimal>
Returns the OKLCH coordinates of the color.
-
#to_oklch ⇒ Abachrome::Color
Converts the current color to the OKLCH color space.
-
#to_oklch! ⇒ Abachrome::Color
Converts the color to OKLCH color space in-place.
Instance Method Details
#chroma ⇒ AbcDecimal
Returns the chroma value of the color by converting it to the OKLCH color space. Chroma represents color intensity or saturation in the OKLCH color space.
74 75 76 |
# File 'lib/abachrome/color_mixins/to_oklch.rb', line 74 def chroma to_oklch.coordinates[1] end |
#hue ⇒ AbcDecimal
Returns the hue value of the color in the OKLCH color space.
from the OKLCH color space representation.
82 83 84 |
# File 'lib/abachrome/color_mixins/to_oklch.rb', line 82 def hue to_oklch.coordinates[2] end |
#lightness ⇒ AbcDecimal
Returns the lightness component of the color in the OKLCH color space. This method provides direct access to the first coordinate of the OKLCH representation of the color, which represents perceptual lightness.
typically in the range of 0.0 to 1.0, where 0.0 is black and 1.0 is white
66 67 68 |
# File 'lib/abachrome/color_mixins/to_oklch.rb', line 66 def lightness to_oklch.coordinates[0] end |
#oklch_array ⇒ Array<Numeric>
Returns the OKLCH coordinates of the color as an array.
Converts the current color to OKLCH color space and returns its coordinates as an array. The OKLCH color space represents colors using Lightness, Chroma, and Hue components in a perceptually uniform way.
103 104 105 |
# File 'lib/abachrome/color_mixins/to_oklch.rb', line 103 def oklch_array to_oklch.coordinates end |
#oklch_values ⇒ Array<AbcDecimal>
Returns the OKLCH coordinates of the color.
- lightness: perceptual lightness component (0-1)
- chroma: colorfulness/saturation component
- hue: hue angle in degrees (0-360)
92 93 94 |
# File 'lib/abachrome/color_mixins/to_oklch.rb', line 92 def oklch_values to_oklch.coordinates end |
#to_oklch ⇒ Abachrome::Color
Converts the current color to the OKLCH color space.
This method transforms the color into the perceptually uniform OKLCH color space. If the color is already in OKLCH, it returns itself unchanged. If the color is in OKLAB, it directly converts from OKLAB to OKLCH. For all other color spaces, it first converts to OKLAB as an intermediate step, then converts to OKLCH.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/abachrome/color_mixins/to_oklch.rb', line 33 def to_oklch return self if color_space.name == :oklch if color_space.name == :oklab Converters::OklabToOklch.convert(self) else # For other color spaces, convert to OKLab first oklab_color = to_oklab Converters::OklabToOklch.convert(oklab_color) end end |
#to_oklch! ⇒ Abachrome::Color
Converts the color to OKLCH color space in-place. This method transforms the current color to OKLCH color space, modifying the original object instead of creating a new one. If the color is already in OKLCH space, no conversion is performed.
51 52 53 54 55 56 57 58 |
# File 'lib/abachrome/color_mixins/to_oklch.rb', line 51 def to_oklch! unless color_space.name == :oklch oklch_color = to_oklch @color_space = oklch_color.color_space @coordinates = oklch_color.coordinates end self end |