Skip to content
party.js logoparty.js logo

ReferenceSamplersFunction

gradient()

Picks random colors from a gradient.

function gradient(
colors: (string | Color)[] | GradientStop[],
): SamplerFn<Color>;

Creates a sampler that picks a random color from a gradient.

Each particle gets a random position along the gradient, with every position being equally likely. This means that the colors appear in the proportions the gradient gives them. Plain colors are spaced evenly, and one can use stops to give some colors a higher chance than others.

colors(string | Color)[] | GradientStop[]

The colors, evenly spaced, or explicit stops.

PartyJSError

If no colors or stops are given, if a stop’s offset is outside [0, 1], or if a color string is invalid.