Raxol.Style.Colors.Advanced (Raxol v0.2.0)
View SourceProvides advanced color handling capabilities for the terminal.
Features:
- Color blending and mixing
- Custom color palettes
- Enhanced color adaptation
- Color space conversions
- Color harmony generation
Summary
Functions
Adapts a color to the current terminal capabilities with advanced options.
Blends two colors together with the given ratio.
Converts a color to a different color space.
Creates a gradient between two colors with the specified number of steps.
Creates a color harmony based on the input color.
Types
@type color() :: Raxol.Style.Colors.Color.t()
@type color_space() :: :rgb | :hsl | :lab | :xyz
@type palette() :: Raxol.Style.Colors.Palette.t()
Functions
Adapts a color to the current terminal capabilities with advanced options.
Parameters
color
- The color to adaptoptions
- Adaptation options:preserve_brightness
- Try to maintain perceived brightness:enhance_contrast
- Increase contrast when possible:color_blind_safe
- Ensure color blind friendly colors
Examples
iex> color = Color.from_hex("#FF0000")
iex> adapted = Advanced.adapt_color_advanced(color, preserve_brightness: true)
iex> adapted.hex
"#FF0000" # If terminal supports true color
Blends two colors together with the given ratio.
Parameters
color1
- First colorcolor2
- Second colorratio
- Blend ratio (0.0 to 1.0, where 0.0 is color1 and 1.0 is color2)
Examples
iex> color1 = Color.from_hex("#FF0000")
iex> color2 = Color.from_hex("#0000FF")
iex> blended = Advanced.blend_colors(color1, color2, 0.5)
iex> blended.hex
"#800080" # Purple
Converts a color to a different color space.
Parameters
color
- The color to converttarget_space
- The target color space (:rgb, :hsl, :lab, or :xyz)
Examples
iex> color = Color.from_hex("#FF0000")
iex> hsl = Advanced.convert_color_space(color, :hsl)
iex> hsl
%{h: 0, s: 100, l: 50}
Creates a gradient between two colors with the specified number of steps.
Parameters
color1
- Start colorcolor2
- End colorsteps
- Number of steps in the gradient
Examples
iex> color1 = Color.from_hex("#FF0000")
iex> color2 = Color.from_hex("#0000FF")
iex> gradient = Advanced.create_gradient(color1, color2, 3)
iex> Enum.map(gradient, & &1.hex)
["#FF0000", "#800080", "#0000FF"]
Creates a color harmony based on the input color.
Parameters
color
- The base colorharmony_type
- Type of harmony (:complementary, :analogous, :triadic, :tetradic)
Examples
iex> color = Color.from_hex("#FF0000")
iex> harmony = Advanced.create_harmony(color, :complementary)
iex> Enum.map(harmony, & &1.hex)
["#FF0000", "#00FFFF"]