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

View Source

Manages collections of related colors as palettes. Provides standard palettes and custom palette creation.

Examples

# Using standard palettes
palette = Raxol.Style.Colors.Palette.standard_16()
solarized = Raxol.Style.Colors.Palette.solarized()

# Creating a custom palette from a base color
base_color = Raxol.Style.Colors.Color.from_hex("#4285F4")  # Google Blue
custom_palette = Raxol.Style.Colors.Palette.from_base_color(base_color)

# Accessing colors from a palette
primary = Raxol.Style.Colors.Palette.get_color(palette, :primary)
background = Raxol.Style.Colors.Palette.get_color(palette, :background)

Summary

Functions

Adds a color to a palette with the given name.

Creates an analogous color palette based on a base color.

Creates an ANSI 256 color palette. Currently this is a placeholder that returns the standard 16 colors.

Creates a complementary palette based on a base color.

Creates a Dracula color palette.

Creates a new palette from a base color.

Gets a color from a palette by name.

Merges two palettes, with the second palette's colors taking precedence.

Creates a monochromatic color palette with specified number of steps.

Creates a Nord color palette.

Removes a color from a palette by name.

Creates a Solarized color palette.

Creates a standard 16-color ANSI palette.

Creates a triadic color palette based on a base color.

Types

t()

@type t() :: %Raxol.Style.Colors.Palette{
  accent: atom() | [atom()],
  background: atom(),
  colors: %{optional(atom()) => Raxol.Style.Colors.Color.t()},
  foreground: atom(),
  name: String.t(),
  primary: atom(),
  secondary: atom()
}

Functions

add_color(palette, name, color)

Adds a color to a palette with the given name.

Examples

iex> palette = Raxol.Style.Colors.Palette.standard_16()
iex> color = Raxol.Style.Colors.Color.from_hex("#FF00FF")
iex> updated = Raxol.Style.Colors.Palette.add_color(palette, :hot_pink, color)
iex> Raxol.Style.Colors.Palette.get_color(updated, :hot_pink) == color
true

analogous(base_color)

Creates an analogous color palette based on a base color.

Examples

iex> base = Raxol.Style.Colors.Color.from_hex("#4285F4")
iex> palette = Raxol.Style.Colors.Palette.analogous(base)
iex> palette.name
"Analogous"

ansi_256()

Creates an ANSI 256 color palette. Currently this is a placeholder that returns the standard 16 colors.

Examples

iex> palette = Raxol.Style.Colors.Palette.ansi_256()
iex> palette.name
"ANSI 256"

complementary(base_color)

Creates a complementary palette based on a base color.

Examples

iex> base = Raxol.Style.Colors.Color.from_hex("#4285F4")
iex> palette = Raxol.Style.Colors.Palette.complementary(base)
iex> palette.name
"Complementary"

dracula()

Creates a Dracula color palette.

Examples

iex> palette = Raxol.Style.Colors.Palette.dracula()
iex> palette.name
"Dracula"

from_base_color(base_color, name \\ "Custom")

Creates a new palette from a base color.

Examples

iex> base = Raxol.Style.Colors.Color.from_hex("#4285F4")
iex> palette = Raxol.Style.Colors.Palette.from_base_color(base)
iex> palette.name
"Custom"

get_color(palette, name)

Gets a color from a palette by name.

Examples

iex> palette = Raxol.Style.Colors.Palette.standard_16()
iex> color = Raxol.Style.Colors.Palette.get_color(palette, :red)
iex> color.hex
"#800000"

merge_palettes(palette1, palette2)

Merges two palettes, with the second palette's colors taking precedence.

Examples

iex> p1 = Raxol.Style.Colors.Palette.standard_16()
iex> p2 = Raxol.Style.Colors.Palette.solarized()
iex> merged = Raxol.Style.Colors.Palette.merge_palettes(p1, p2)
iex> merged.name
"ANSI 16 + Solarized"

monochromatic(base_color, steps \\ 5)

Creates a monochromatic color palette with specified number of steps.

Examples

iex> base = Raxol.Style.Colors.Color.from_hex("#4285F4")
iex> palette = Raxol.Style.Colors.Palette.monochromatic(base, 5)
iex> palette.name
"Monochromatic"

nord()

Creates a Nord color palette.

Examples

iex> palette = Raxol.Style.Colors.Palette.nord()
iex> palette.name
"Nord"

remove_color(palette, name)

Removes a color from a palette by name.

Examples

iex> palette = Raxol.Style.Colors.Palette.standard_16()
iex> updated = Raxol.Style.Colors.Palette.remove_color(palette, :red)
iex> Raxol.Style.Colors.Palette.get_color(updated, :red)
nil

solarized()

Creates a Solarized color palette.

Examples

iex> palette = Raxol.Style.Colors.Palette.solarized()
iex> palette.name
"Solarized"

standard_16()

Creates a standard 16-color ANSI palette.

Examples

iex> palette = Raxol.Style.Colors.Palette.standard_16()
iex> Map.keys(palette.colors) |> length()
16

triadic(base_color)

Creates a triadic color palette based on a base color.

Examples

iex> base = Raxol.Style.Colors.Color.from_hex("#4285F4")
iex> palette = Raxol.Style.Colors.Palette.triadic(base)
iex> palette.name
"Triadic"