plushie/prop/gradient

Gradient type for background fills.

Supports linear gradients defined by start/end coordinates and a list of color stops. Each stop has an offset (0.0 to 1.0) and a Color value (from prop/color).

Wire format

Uses coordinate-based format matching the canvas gradient API:

{
  "type": "linear",
  "start": [0, 0],
  "end": [100, 100],
  "stops": [[0.0, "#ff0000"], [1.0, "#0000ff"]]
}

Types

pub type Gradient {
  Gradient(
    from: #(Float, Float),
    to: #(Float, Float),
    stops: List(GradientStop),
  )
}

Constructors

  • Gradient(
      from: #(Float, Float),
      to: #(Float, Float),
      stops: List(GradientStop),
    )
pub type GradientStop {
  GradientStop(offset: Float, color: color.Color)
}

Constructors

Values

pub fn linear(
  from: #(Float, Float),
  to: #(Float, Float),
  stops: List(GradientStop),
) -> Gradient

Create a linear gradient between two coordinate points.

pub fn linear_from_angle(
  angle_degrees: Float,
  stops: List(GradientStop),
) -> Gradient

Create 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.

pub fn stop(offset: Float, c: color.Color) -> GradientStop

Create a gradient stop.

pub fn to_prop_value(g: Gradient) -> node.PropValue

Encode a Gradient to its wire-format PropValue.

Search Document