Linear and multi-stop color gradient generation.
All operations are pure functions returning lists of RGB tuples or iodata-ready ANSI strings for terminal output.
Type aliases defined here reference the canonical types in Pote.
Usage
iex> Pote.Gradients.linear({255, 0, 0}, {0, 0, 255}, 5)
[{255, 0, 0}, {191, 0, 64}, {128, 0, 128}, {64, 0, 191}, {0, 0, 255}]
iex> Pote.Gradients.apply_to_text("Hello", {255, 0, 0}, {0, 0, 255})
# returns iodata with ANSI sequences applying the gradient to each character
Summary
Functions
Applies a gradient background to a text string.
Applies a gradient to a text string, coloring each character individually.
Generates a linear gradient between two colors.
Generates a multi-stop gradient across a list of colors.
Converts a list of RGB tuples to their corresponding HSL tuples.
Generates a vertical gradient as a list of lines where each line gets a different color stop.
Types
@type direction() :: :left_to_right | :right_to_left | :top_to_bottom | :bottom_to_top
@type rgb() :: Pote.rgb()
Functions
Applies a gradient background to a text string.
Similar to apply_to_text/4 but applies the gradient to the background color
instead of the foreground, using a contrasting text color.
Parameters
text- The string to colorizefrom- Start background colorto- End background colortext_color- Foreground color for the text (default: white)
Applies a gradient to a text string, coloring each character individually.
Returns iodata with ANSI escape sequences applying the gradient
from from color to to color across the full string length.
Parameters
text- The string to colorizefrom- Start colorto- End colordirection- Direction of the gradient (default::left_to_right)
Examples
iex> apply_to_text("Hi", {255, 0, 0}, {0, 0, 255})
# iodata with each char in a gradient color
@spec linear(rgb(), rgb(), pos_integer()) :: [rgb()]
Generates a linear gradient between two colors.
Returns steps RGB tuples evenly interpolated from from to to.
Parameters
from- Start color as RGB tupleto- End color as RGB tuplesteps- Number of color stops (minimum 2)
Examples
iex> linear({255, 0, 0}, {0, 0, 255}, 3)
[{255, 0, 0}, {128, 0, 128}, {0, 0, 255}]
@spec multicolor([rgb()], pos_integer()) :: [rgb()]
Generates a multi-stop gradient across a list of colors.
Returns steps total RGB tuples interpolated across all provided
color stops with equal spacing between stops.
Parameters
colors- List of RGB tuples (minimum 2)steps- Total number of output colors
Examples
iex> multicolor([{255,0,0}, {0,255,0}, {0,0,255}], 5)
[{255, 0, 0}, {128, 128, 0}, {0, 255, 0}, {0, 128, 128}, {0, 0, 255}]
@spec to_hsl_stops([rgb()]) :: [Pote.Conversions.hsl()]
Converts a list of RGB tuples to their corresponding HSL tuples.
Useful for analyzing or transforming gradient stops in HSL space.
@spec vertical_fill(rgb(), rgb(), pos_integer(), pos_integer(), String.t()) :: iodata()
Generates a vertical gradient as a list of lines where each line gets a different color stop.
Useful for rendering gradient backgrounds in multi-line UI areas.
Parameters
from- Top colorto- Bottom colorlines- Number of lines (height of the area)width- Width in characters of each linechar- Fill character (default: space" ")