Gradient type for container and style backgrounds.
Build gradients with linear/3:
Plushie.Type.Gradient.linear({0, 0}, {100, 100}, [
{0.0, "#ff0000"},
{0.5, "#00ff00"},
{1.0, "#0000ff"}
])Or from an angle with linear_from_angle/2:
Plushie.Type.Gradient.linear_from_angle(90, [
{0.0, "#ff0000"},
{1.0, "#0000ff"}
])Stop colors accept any form Plushie.Type.Color.cast/1 supports
(named atoms, hex strings, RGBA maps). They are normalized to
canonical hex strings during construction.
Wire format
Uses the same coordinate-based format as Plushie.Canvas.Gradient:
%{
type: "linear",
start: [0, 0],
end: [100, 100],
stops: [[0.0, "#ff0000"], [1.0, "#0000ff"]]
}
Summary
Types
A gradient color stop: {offset, color} where offset is 0.0-1.0.
Color input for gradient stops: any form Color.cast/1 supports.
Functions
Validates a gradient value.
Creates a linear gradient between two coordinate points.
Creates a linear gradient from an angle (degrees) and stops.
Types
A gradient color stop: {offset, color} where offset is 0.0-1.0.
@type stop_color() :: Plushie.Type.Color.input()
Color input for gradient stops: any form Color.cast/1 supports.
Functions
Validates a gradient value.
Accepts %Gradient{} structs directly, or plain maps with
from/to coordinate tuples and stops.
@spec linear( from :: {number(), number()}, to :: {number(), number()}, stops :: [{number(), stop_color()}] ) :: t()
Creates a linear gradient between two coordinate points.
@spec linear_from_angle(angle :: number(), stops :: [{number(), stop_color()}]) :: t()
Creates a linear gradient from an angle (degrees) and stops.
The angle is converted to start/end coordinates on a unit square (0,0 to 1,1). Use this when you want angle-based gradients without computing coordinates manually.