EDA.Color (EDA v0.3.0)

Copy Markdown View Source

Discord embed and component color utilities.

Provides named color constants, hex parsing, and cryptographically random color generation for embeds and components.

Named colors

EDA.Color.blurple()   #=> 0x5865F2
EDA.Color.red()       #=> 0xED4245
EDA.Color.random()    #=> 0xA3F29C  (different every call)

Usage with embeds

import EDA.Embed

new()
|> color(:random)
|> title("Every embed gets a unique color")

Usage with components (V2 containers)

import EDA.Component

container([...], color: EDA.Color.random())

Summary

Functions

Returns a map of all named colors.

Returns a sorted list of all named color atoms.

Returns the black color value (0x0).

Returns the blue color value (0x3498DB).

Returns the blurple color value (0x5865F2).

Returns the coral color value (0xFF7F50).

Returns the cyan color value (0xFFFF).

Returns the dark_blue color value (0x206694).

Returns the dark_gold color value (0xC27C0E).

Returns the dark_green color value (0x1F8B4C).

Returns the dark_grey color value (0x546E7A).

Returns the dark_purple color value (0x71368A).

Returns the dark_red color value (0x992D22).

Returns the dark_teal color value (0x11806A).

Returns the dark_theme color value (0x2C2F33).

Returns the fuchsia color value (0xEB459E).

Returns the gold color value (0xF1C40F).

Returns the green color value (0x57F287).

Returns the greyple color value (0x99AAB5).

Returns the indigo color value (0x4B0082).

Returns the lavender color value (0xE6E6FA).

Returns the light_grey color value (0x979C9F).

Returns the lime color value (0x2ECC71).

Returns the mint color value (0x98FF98).

Returns the orange color value (0xE67E22).

Returns the pink color value (0xFF69B4).

Returns the purple color value (0x9B59B6).

Returns a cryptographically random color (0x000000..0xFFFFFF).

Returns the red color value (0xED4245).

Resolves a color value from a name atom, integer, hex string, or :random.

Returns the salmon color value (0xFA8072).

Returns the teal color value (0x1ABC9C).

Returns the white color value (0xFFFFFF).

Returns the yellow color value (0xFEE75C).

Functions

all()

@spec all() :: %{required(atom()) => non_neg_integer()}

Returns a map of all named colors.

all_names()

@spec all_names() :: [atom()]

Returns a sorted list of all named color atoms.

black()

@spec black() :: non_neg_integer()

Returns the black color value (0x0).

blue()

@spec blue() :: non_neg_integer()

Returns the blue color value (0x3498DB).

blurple()

@spec blurple() :: non_neg_integer()

Returns the blurple color value (0x5865F2).

coral()

@spec coral() :: non_neg_integer()

Returns the coral color value (0xFF7F50).

cyan()

@spec cyan() :: non_neg_integer()

Returns the cyan color value (0xFFFF).

dark_blue()

@spec dark_blue() :: non_neg_integer()

Returns the dark_blue color value (0x206694).

dark_gold()

@spec dark_gold() :: non_neg_integer()

Returns the dark_gold color value (0xC27C0E).

dark_green()

@spec dark_green() :: non_neg_integer()

Returns the dark_green color value (0x1F8B4C).

dark_grey()

@spec dark_grey() :: non_neg_integer()

Returns the dark_grey color value (0x546E7A).

dark_purple()

@spec dark_purple() :: non_neg_integer()

Returns the dark_purple color value (0x71368A).

dark_red()

@spec dark_red() :: non_neg_integer()

Returns the dark_red color value (0x992D22).

dark_teal()

@spec dark_teal() :: non_neg_integer()

Returns the dark_teal color value (0x11806A).

dark_theme()

@spec dark_theme() :: non_neg_integer()

Returns the dark_theme color value (0x2C2F33).

fuchsia()

@spec fuchsia() :: non_neg_integer()

Returns the fuchsia color value (0xEB459E).

gold()

@spec gold() :: non_neg_integer()

Returns the gold color value (0xF1C40F).

green()

@spec green() :: non_neg_integer()

Returns the green color value (0x57F287).

greyple()

@spec greyple() :: non_neg_integer()

Returns the greyple color value (0x99AAB5).

indigo()

@spec indigo() :: non_neg_integer()

Returns the indigo color value (0x4B0082).

lavender()

@spec lavender() :: non_neg_integer()

Returns the lavender color value (0xE6E6FA).

light_grey()

@spec light_grey() :: non_neg_integer()

Returns the light_grey color value (0x979C9F).

lime()

@spec lime() :: non_neg_integer()

Returns the lime color value (0x2ECC71).

mint()

@spec mint() :: non_neg_integer()

Returns the mint color value (0x98FF98).

orange()

@spec orange() :: non_neg_integer()

Returns the orange color value (0xE67E22).

pink()

@spec pink() :: non_neg_integer()

Returns the pink color value (0xFF69B4).

purple()

@spec purple() :: non_neg_integer()

Returns the purple color value (0x9B59B6).

random()

@spec random() :: non_neg_integer()

Returns a cryptographically random color (0x000000..0xFFFFFF).

Uses :crypto.strong_rand_bytes/1 for uniform distribution — every color in the 16.7M range has equal probability. No repeating patterns.

Examples

EDA.Color.random()  #=> 0xA3F29C
EDA.Color.random()  #=> 0x1B44E7

red()

@spec red() :: non_neg_integer()

Returns the red color value (0xED4245).

resolve(name)

@spec resolve(atom() | non_neg_integer() | String.t()) :: non_neg_integer()

Resolves a color value from a name atom, integer, hex string, or :random.

Examples

EDA.Color.resolve(:blurple)   #=> 0x5865F2
EDA.Color.resolve(:random)    #=> 0x...... (random)
EDA.Color.resolve(0xFF0000)   #=> 0xFF0000
EDA.Color.resolve("#FF0000")  #=> 0xFF0000

salmon()

@spec salmon() :: non_neg_integer()

Returns the salmon color value (0xFA8072).

teal()

@spec teal() :: non_neg_integer()

Returns the teal color value (0x1ABC9C).

white()

@spec white() :: non_neg_integer()

Returns the white color value (0xFFFFFF).

yellow()

@spec yellow() :: non_neg_integer()

Returns the yellow color value (0xFEE75C).