Module: Abachrome::ColorMixins::ToOklab
- Defined in:
- lib/abachrome/color_mixins/to_oklab.rb
Instance Method Summary collapse
-
#a ⇒ AbcDecimal
Returns the ‘a’ component from the OKLAB color space (green-red axis).
-
#b ⇒ AbcDecimal
Returns the B value of the color in OKLAB color space.
-
#l ⇒ AbcDecimal
Returns the L (Lightness) component from the OKLAB color space.
-
#lightness ⇒ AbcDecimal
Returns the lightness component (L) of the color in the OKLAB color space.
-
#oklab_array ⇒ Array<AbcDecimal>
Returns an array representation of the color’s coordinates in the OKLAB color space.
-
#oklab_values ⇒ Array
Returns the OKLAB color space coordinates for this color.
-
#to_oklab ⇒ Abachrome::Color
Converts the current color to the OKLAB color space.
-
#to_oklab! ⇒ Abachrome::Color
Converts the color to the OKLAB color space in place.
Instance Method Details
#a ⇒ AbcDecimal
Returns the ‘a’ component from the OKLAB color space (green-red axis).
The ‘a’ component in OKLAB represents the position on the green-red axis, with negative values being more green and positive values being more red.
82 83 84 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 82 def a to_oklab.coordinates[1] end |
#b ⇒ AbcDecimal
Returns the B value of the color in OKLAB color space.
This method first converts the color to OKLAB color space if needed, then extracts the B component (blue-yellow axis), which is the third coordinate in the OKLAB model.
93 94 95 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 93 def b to_oklab.coordinates[2] end |
#l ⇒ AbcDecimal
Returns the L (Lightness) component from the OKLAB color space.
The L value represents perceptual lightness in the OKLAB color space, typically ranging from 0 (black) to 1 (white).
71 72 73 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 71 def l to_oklab.coordinates[0] end |
#lightness ⇒ AbcDecimal
Returns the lightness component (L) of the color in the OKLAB color space. The lightness value ranges from 0 (black) to 1 (white) and represents the perceived lightness of the color.
61 62 63 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 61 def lightness to_oklab.coordinates[0] end |
#oklab_array ⇒ Array<AbcDecimal>
Returns an array representation of the color’s coordinates in the OKLAB color space.
in the OKLAB color space in the order [L, a, b]
108 109 110 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 108 def oklab_array to_oklab.coordinates end |
#oklab_values ⇒ Array
Returns the OKLAB color space coordinates for this color.
100 101 102 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 100 def oklab_values to_oklab.coordinates end |
#to_oklab ⇒ Abachrome::Color
Converts the current color to the OKLAB color space.
If the color is already in OKLAB, it returns the color unchanged. Otherwise, it uses the Converter to transform the color to OKLAB.
31 32 33 34 35 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 31 def to_oklab return self if color_space.name == :oklab Converter.convert(self, :oklab) end |
#to_oklab! ⇒ Abachrome::Color
Converts the color to the OKLAB color space in place. This method transforms the current color into OKLAB space, modifying the original object by updating its color space and coordinates if not already in OKLAB.
color = Abachrome::Color.from_hex(“#ff5500”) color.to_oklab! # Color now uses OKLAB color space
47 48 49 50 51 52 53 54 |
# File 'lib/abachrome/color_mixins/to_oklab.rb', line 47 def to_oklab! unless color_space.name == :oklab oklab_color = to_oklab @color_space = oklab_color.color_space @coordinates = oklab_color.coordinates end self end |