Pote.ColorInfo (Pote v1.0.0)

Copy Markdown View Source

Structured representation of a color in all supported formats.

Pote.ColorInfo holds a color's values across multiple color spaces (RGB, HEX, HSL, HSV, CMYK, XTerm256, ARGB) and provides convenient methods for harmonies, lightness adjustments, and ANSI output.

Create a ColorInfo from any valid color input using new/1.

Examples

iex> ci = Pote.ColorInfo.new("#FF8000")
iex> ci.rgb
{255, 128, 0}
iex> ci.hex
"#FF8000"

Summary

Functions

Returns two analogous colors (offset by angle degrees).

Returns the map of basic ANSI colors.

Returns the complementary color (180 opposite on the wheel).

Returns a darker variant of the color blended with black.

Returns a lighter variant of the color blended with white.

Finds the nearest basic ANSI color name for a given RGB value.

Creates a new empty ColorInfo structure.

Creates a new ColorInfo from various inputs.

Converts ColorInfo to ANSI escape code.

Returns the triad harmony (base + 120 + 240).

Types

argb()

@type argb() :: {0..255, 0..255, 0..255, 0..255}

cmyk()

@type cmyk() :: {number(), number(), number(), number()}

hsl()

@type hsl() :: {number(), number(), number()}

hsv()

@type hsv() :: {number(), number(), number()}

rgb()

@type rgb() :: {0..255, 0..255, 0..255}

t()

@type t() :: %Pote.ColorInfo{
  argb: argb() | nil,
  cmyk: cmyk() | nil,
  display: any() | nil,
  format: atom() | nil,
  hex: String.t() | nil,
  hsl: hsl() | nil,
  hsv: hsv() | nil,
  inverted: boolean(),
  name: atom() | nil,
  rgb: rgb() | nil,
  xterm256: 0..255 | nil
}

Functions

analogous(ci, angle \\ 30.0)

@spec analogous(t(), number()) :: [t()]

Returns two analogous colors (offset by angle degrees).

basic_colors()

@spec basic_colors() :: %{required(atom()) => {0..255, 0..255, 0..255}}

Returns the map of basic ANSI colors.

complementary(ci)

@spec complementary(t()) :: t()

Returns the complementary color (180 opposite on the wheel).

darker(ci, factor)

@spec darker(t(), number()) :: t()

Returns a darker variant of the color blended with black.

lighter(ci, factor)

@spec lighter(t(), number()) :: t()

Returns a lighter variant of the color blended with white.

nearest_basic_color(rgb)

@spec nearest_basic_color(rgb()) :: atom()

Finds the nearest basic ANSI color name for a given RGB value.

Examples

iex> Pote.ColorInfo.nearest_basic_color({255, 0, 0})
:red

iex> Pote.ColorInfo.nearest_basic_color({250, 10, 5})
:red

new()

@spec new() :: t()

Creates a new empty ColorInfo structure.

new(color, opts \\ [])

@spec new(
  any(),
  keyword()
) :: t()

Creates a new ColorInfo from various inputs.

to_ansi(arg1)

@spec to_ansi(t()) :: String.t()

Converts ColorInfo to ANSI escape code.

triad(ci)

@spec triad(t()) :: [t()]

Returns the triad harmony (base + 120 + 240).