Raxol.Style.Colors.Advanced (Raxol v0.2.0)

View Source

Provides 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

color()

@type color() :: Raxol.Style.Colors.Color.t()

color_space()

@type color_space() :: :rgb | :hsl | :lab | :xyz

palette()

@type palette() :: Raxol.Style.Colors.Palette.t()

Functions

adapt_color_advanced(color, options \\ [])

Adapts a color to the current terminal capabilities with advanced options.

Parameters

  • color - The color to adapt
  • options - 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

blend_colors(color1, color2, ratio)

Blends two colors together with the given ratio.

Parameters

  • color1 - First color
  • color2 - Second color
  • ratio - 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

convert_color_space(color, target_space)

Converts a color to a different color space.

Parameters

  • color - The color to convert
  • target_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}

create_gradient(color1, color2, steps)

Creates a gradient between two colors with the specified number of steps.

Parameters

  • color1 - Start color
  • color2 - End color
  • steps - 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"]

create_harmony(color, harmony_type)

Creates a color harmony based on the input color.

Parameters

  • color - The base color
  • harmony_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"]