Raxol.Utils.ColorConversion (Raxol v2.0.1)

View Source

Utility 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

hex_to_rgb(arg1)

@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_color(from_color, to_color, progress)

@spec interpolate_color(String.t(), String.t(), float()) :: String.t()

Interpolate between two colors.

Examples

iex> Raxol.Utils.ColorConversion.interpolate_color("#000000", "#FFFFFF", 0.5)
"#7f7f7f"

rgb_to_hex(arg)

@spec rgb_to_hex({number(), number(), number()}) :: String.t()

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"