Raxol.Utils.ColorConversion (Raxol v2.0.1)
View SourceUtility functions for color conversions between hex and RGB formats.
Summary
Functions
Convert hex color to RGB tuple.
Interpolate between two colors.
Convert RGB tuple to hex color.
Functions
@spec hex_to_rgb(String.t()) :: {non_neg_integer(), non_neg_integer(), non_neg_integer()}
Convert hex color to RGB tuple.
Examples
iex> Raxol.Utils.ColorConversion.hex_to_rgb("#FF0000")
{255, 0, 0}
iex> Raxol.Utils.ColorConversion.hex_to_rgb("#00FF00")
{0, 255, 0}
iex> Raxol.Utils.ColorConversion.hex_to_rgb("invalid")
{0, 0, 0}
Interpolate between two colors.
Examples
iex> Raxol.Utils.ColorConversion.interpolate_color("#000000", "#FFFFFF", 0.5)
"#7f7f7f"
Convert RGB tuple to hex color.
Examples
iex> Raxol.Utils.ColorConversion.rgb_to_hex({255, 0, 0})
"#ff0000"
iex> Raxol.Utils.ColorConversion.rgb_to_hex({0, 255, 0})
"#00ff00"