Tint v0.3.0 Tint.RGB View Source
A color in the RGB (red, green, blue) colorspace.
Link to this section Summary
Functions
Calculates the distance of two colors using the Euclidean distance algorithm.
Builds a new RGB color from the given hex code.
Builds a new RGB color from the given hex code. Raises when the given hex code is invalid.
Builds a new RGB color from red, green and blue color ratios.
Converts a tuple containing hue, saturation and value into a Tint.RGB
struct.
A version of the Euclidean distance algorithm that uses weights that are optimized for human color perception.
Finds the nearest color for the specified color using the given color palette and an optional distance algorithm.
Builds a new RGB color from red, green and blue color parts. Please always use this function to build a new RGB color.
Converts a RGB color to a hex code.
Builds a tuple containing the ratios of the red, green and blue components of a given color.
Converts RGB color into a tuple containing the red, green and blue parts.
Link to this section Types
t()
View Source
t() :: %Tint.RGB{
blue: non_neg_integer(),
green: non_neg_integer(),
red: non_neg_integer()
}
t() :: %Tint.RGB{ blue: non_neg_integer(), green: non_neg_integer(), red: non_neg_integer() }
Link to this section Functions
euclidean_distance(color, other_color, opts \\ []) View Source (since 0.2.0)
Calculates the distance of two colors using the Euclidean distance algorithm.
Options
:weights
- A tuple defining the weights for the red, green and blue color components. Defaults to{1, 1, 1}
.
from_hex(code) View Source
Builds a new RGB color from the given hex code.
Examples
iex> Tint.RGB.from_hex("#FF7F1E")
{:ok, %Tint.RGB{red: 255, green: 127, blue: 30}}
iex> Tint.RGB.from_hex("invalid")
:error
from_hex!(code) View Source
Builds a new RGB color from the given hex code. Raises when the given hex code is invalid.
Examples
iex> Tint.RGB.from_hex!("#FF7F1E")
#Tint.RGB<255,127,30>
iex> Tint.RGB.from_hex!("invalid")
** (ArgumentError) Invalid hex code: invalid
from_ratios(red_ratio, green_ratio, blue_ratio) View Source
Builds a new RGB color from red, green and blue color ratios.
Example
iex> Tint.RGB.from_ratios(1, 0.5, 0)
#Tint.RGB<255,128,0>
from_tuple(arg) View Source
Converts a tuple containing hue, saturation and value into a Tint.RGB
struct.
Example
iex> Tint.RGB.from_tuple({255, 127, 30})
#Tint.RGB<255,127,30>
human_euclidean_distance(color, other_color)
View Source
(since 0.2.0)
human_euclidean_distance(t(), Tint.RGB.Convertible.t()) :: float()
human_euclidean_distance(t(), Tint.RGB.Convertible.t()) :: float()
A version of the Euclidean distance algorithm that uses weights that are optimized for human color perception.
nearest(color, palette, distance_algorithm \\ &human_euclidean_distance/2)
View Source
(since 0.2.0)
nearest(t(), [Tint.RGB.Convertible.t()], (t(), t() -> number())) ::
nil | Tint.RGB.Convertible.t()
nearest(t(), [Tint.RGB.Convertible.t()], (t(), t() -> number())) :: nil | Tint.RGB.Convertible.t()
Finds the nearest color for the specified color using the given color palette and an optional distance algorithm.
new(red, green, blue) View Source
Builds a new RGB color from red, green and blue color parts. Please always use this function to build a new RGB color.
Examples
iex> Tint.RGB.new(0, 0, 0)
#Tint.RGB<0,0,0>
iex> Tint.RGB.new(255, 127, 30)
#Tint.RGB<255,127,30>
iex> Tint.RGB.new(256, -1, 0)
** (Tint.OutOfRangeError) Value 256 is out of range [0,255]
to_hex(color) View Source
Converts a RGB color to a hex code.
Example
iex> Tint.RGB.to_hex(%Tint.RGB{red: 255, green: 127, blue: 30})
"#FF7F1E"
to_ratios(color) View Source
Builds a tuple containing the ratios of the red, green and blue components of a given color.
to_tuple(color)
View Source
to_tuple(t()) :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}
to_tuple(t()) :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}
Converts RGB color into a tuple containing the red, green and blue parts.
Example
iex> Tint.RGB.to_tuple(%Tint.RGB{red: 255, green: 127, blue: 30})
{255, 127, 30}