Module: Abachrome
- Defined in:
- lib/abachrome/converter.rb,
lib/abachrome.rb,
lib/abachrome/color.rb,
lib/abachrome/palette.rb,
lib/abachrome/to_abcd.rb,
lib/abachrome/version.rb,
lib/abachrome/gamut/p3.rb,
lib/abachrome/named/css.rb,
lib/abachrome/gamut/base.rb,
lib/abachrome/gamut/srgb.rb,
lib/abachrome/abc_decimal.rb,
lib/abachrome/color_space.rb,
lib/abachrome/outputs/css.rb,
lib/abachrome/parsers/css.rb,
lib/abachrome/parsers/hex.rb,
lib/abachrome/gamut/rec2020.rb,
lib/abachrome/named/tailwind.rb,
lib/abachrome/converters/base.rb,
lib/abachrome/illuminants/d50.rb,
lib/abachrome/illuminants/d55.rb,
lib/abachrome/illuminants/d65.rb,
lib/abachrome/illuminants/d75.rb,
lib/abachrome/color_models/hsv.rb,
lib/abachrome/color_models/lms.rb,
lib/abachrome/color_models/rgb.rb,
lib/abachrome/color_models/xyz.rb,
lib/abachrome/illuminants/base.rb,
lib/abachrome/parsers/tailwind.rb,
lib/abachrome/color_mixins/blend.rb,
lib/abachrome/color_models/oklab.rb,
lib/abachrome/color_models/oklch.rb,
lib/abachrome/color_mixins/lighten.rb,
lib/abachrome/color_mixins/to_lrgb.rb,
lib/abachrome/color_mixins/to_srgb.rb,
lib/abachrome/color_mixins/to_oklab.rb,
lib/abachrome/color_mixins/to_oklch.rb,
lib/abachrome/converters/lms_to_xyz.rb,
lib/abachrome/converters/xyz_to_lms.rb,
lib/abachrome/converters/lms_to_lrgb.rb,
lib/abachrome/converters/lms_to_srgb.rb,
lib/abachrome/converters/lrgb_to_xyz.rb,
lib/abachrome/converters/lrgb_to_srgb.rb,
lib/abachrome/converters/oklab_to_lms.rb,
lib/abachrome/converters/oklch_to_xyz.rb,
lib/abachrome/converters/srgb_to_lrgb.rb,
lib/abachrome/converters/xyz_to_oklab.rb,
lib/abachrome/palette_mixins/resample.rb,
lib/abachrome/converters/lrgb_to_oklab.rb,
lib/abachrome/converters/oklab_to_lrgb.rb,
lib/abachrome/converters/oklab_to_srgb.rb,
lib/abachrome/converters/oklch_to_lrgb.rb,
lib/abachrome/converters/oklch_to_srgb.rb,
lib/abachrome/converters/srgb_to_oklab.rb,
lib/abachrome/converters/srgb_to_oklch.rb,
lib/abachrome/converters/oklab_to_oklch.rb,
lib/abachrome/converters/oklch_to_oklab.rb,
lib/abachrome/color_mixins/to_colorspace.rb,
lib/abachrome/palette_mixins/interpolate.rb,
lib/abachrome/palette_mixins/stretch_luminance.rb
Overview
Abachrome::PaletteMixins::Interpolate - Color palette interpolation functionality
This mixin provides methods for interpolating between adjacent colors in a palette to create smooth color transitions and gradients. The interpolation process inserts new colors between existing palette colors by blending them at calculated intervals, creating smoother color progressions ideal for gradients, color ramps, and visual transitions.
Key features:
-
Insert specified number of interpolated colors between each adjacent color pair
-
Both non-destructive (interpolate) and destructive (interpolate!) variants
-
Uses color blending in the current color space for smooth transitions
-
Maintains original colors as anchor points in the interpolated result
-
High-precision decimal arithmetic for accurate color calculations
-
Preserves alpha values during interpolation process
The mixin includes both immutable methods that return new palette instances and mutable methods that modify the current palette object in place, providing flexibility for different use cases and performance requirements. Interpolation is essential for creating smooth color gradients and ensuring adequate color resolution in palette-based applications.
Defined Under Namespace
Modules: ColorMixins, ColorModels, Converters, Gamut, Illuminants, Named, Outputs, PaletteMixins, Parsers, ToAbcd Classes: AbcDecimal, Color, ColorSpace, Converter, Palette
Constant Summary collapse
- VERSION =
"0.1.5"
Class Method Summary collapse
-
.convert(color, to_space) ⇒ Abachrome::Color
Convert a color from its current color space to another color space.
-
.create_color(space_name, *coordinates, alpha: 1.0) ⇒ Abachrome::Color
Creates a new color in the specified color space with given coordinates and alpha value.
-
.from_hex(hex_str) ⇒ Abachrome::Color
Creates a color object from a hexadecimal color code string.
-
.from_name(color_name) ⇒ Abachrome::Color?
Creates a color object from a CSS color name.
-
.from_oklab(l, a, b, alpha = 1.0) ⇒ Abachrome::Color
Creates a color in the OKLAB color space.
-
.from_oklch(l, a, b, alpha = 1.0) ⇒ Abachrome::Color
Creates a new color from OKLCH color space values.
-
.from_rgb(r, g, b, alpha = 1.0) ⇒ Abachrome::Color
Creates a color object from RGB values.
-
.parse(css_string) ⇒ Abachrome::Color?
Parses a CSS color string and returns a Color object.
-
.register_color_space(name, &block) ⇒ Abachrome::ColorSpace
Register a new color space with the Abachrome library.
-
.register_converter(from_space, to_space, converter) ⇒ void
Register a new color space converter in the Abachrome system.
Class Method Details
.convert(color, to_space) ⇒ Abachrome::Color
Convert a color from its current color space to another color space.
158 159 160 |
# File 'lib/abachrome.rb', line 158 def convert(color, to_space) Converter.convert(color, to_space) end |
.create_color(space_name, *coordinates, alpha: 1.0) ⇒ Abachrome::Color
Creates a new color in the specified color space with given coordinates and alpha value.
80 81 82 83 |
# File 'lib/abachrome.rb', line 80 def create_color(space_name, *coordinates, alpha: 1.0) space = ColorSpace.find(space_name) Color.new(space, coordinates, alpha) end |
.from_hex(hex_str) ⇒ Abachrome::Color
Creates a color object from a hexadecimal color code string.
“#RGB”, “#RRGGBB”, “RGB”, or “RRGGBB”, with or without the leading “#” character. Abachrome.from_hex(“#ff0000”) # => returns a red Color object Abachrome.from_hex(“00ff00”) # => returns a green Color object
127 128 129 |
# File 'lib/abachrome.rb', line 127 def from_hex(hex_str) Parsers::Hex.parse(hex_str) end |
.from_name(color_name) ⇒ Abachrome::Color?
Creates a color object from a CSS color name.
Case-insensitive. nil if the color name is not recognized.
137 138 139 140 141 142 |
# File 'lib/abachrome.rb', line 137 def from_name(color_name) rgb_values = Named::CSS::ColorNames[color_name.downcase] return nil unless rgb_values from_rgb(*rgb_values.map { |v| v / 255.0 }) end |
.from_oklab(l, a, b, alpha = 1.0) ⇒ Abachrome::Color
Creates a color in the OKLAB color space.
103 104 105 |
# File 'lib/abachrome.rb', line 103 def from_oklab(l, a, b, alpha = 1.0) Color.from_oklab(l, a, b, alpha) end |
.from_oklch(l, a, b, alpha = 1.0) ⇒ Abachrome::Color
Creates a new color from OKLCH color space values.
114 115 116 |
# File 'lib/abachrome.rb', line 114 def from_oklch(l, a, b, alpha = 1.0) Color.from_oklch(l, a, b, alpha) end |
.from_rgb(r, g, b, alpha = 1.0) ⇒ Abachrome::Color
Creates a color object from RGB values.
92 93 94 |
# File 'lib/abachrome.rb', line 92 def from_rgb(r, g, b, alpha = 1.0) Color.from_rgb(r, g, b, alpha) end |
.parse(css_string) ⇒ Abachrome::Color?
Parses a CSS color string and returns a Color object.
148 149 150 151 |
# File 'lib/abachrome.rb', line 148 def parse(css_string) require_relative "abachrome/parsers/css" Parsers::CSS.parse(css_string) end |
.register_color_space(name, &block) ⇒ Abachrome::ColorSpace
Register a new color space with the Abachrome library.
167 168 169 |
# File 'lib/abachrome.rb', line 167 def register_color_space(name, &block) ColorSpace.register(name, &block) end |
.register_converter(from_space, to_space, converter) ⇒ void
This method returns an undefined value.
Register a new color space converter in the Abachrome system.
This method allows registering custom converters between color spaces. Converters are used to transform color representations from one color space to another.
181 182 183 |
# File 'lib/abachrome.rb', line 181 def register_converter(from_space, to_space, converter) Converter.register(from_space, to_space, converter) end |