Common Properties
All gradient components share these common properties:| Name | Type | Description |
|---|---|---|
| colors | string[] | Colors to distribute between start and end |
| positions | number[] | Optional relative positions of colors (0-1). Must match the length of colors |
| mode | TileMode | How to handle areas outside the gradient: clamp, repeat, mirror, or decal (default: clamp) |
| flags | number | Set to 1 to interpolate colors in premultiplied space (default: 0) |
| transform | Transform2d | Transform to apply to the gradient (see transformations) |
Linear Gradient
Creates a gradient that transitions colors linearly between two points.Props
| Name | Type | Description |
|---|---|---|
| start | Point | Starting position of the gradient |
| end | Point | Ending position of the gradient |
Example
With Custom Positions
Radial Gradient
Creates a circular gradient radiating from a center point.Props
| Name | Type | Description |
|---|---|---|
| c | Point | Center point of the gradient |
| r | number | Radius of the gradient |
Example
Multiple Color Stops
Sweep Gradient
Creates a gradient that sweeps around a center point like the hands of a clock.Props
| Name | Type | Description |
|---|---|---|
| c | Point | Center of the gradient |
| start | number | Optional start angle in degrees (default: 0) |
| end | number | Optional end angle in degrees (default: 360) |
Example
Partial Sweep
Two-Point Conical Gradient
Creates a gradient between two circles, useful for creating spotlight or cone effects.Props
| Name | Type | Description |
|---|---|---|
| start | Point | Center of the start circle |
| startR | number | Radius of the start circle |
| end | Point | Center of the end circle |
| endR | number | Radius of the end circle |
Example
Tile Modes
Control how gradients behave outside their defined bounds:Clamp (Default)
Extends the edge colors:Repeat
Repeats the gradient:Mirror
Mirrors the gradient:Decal
Draws the gradient only within bounds, transparent elsewhere:Transforming Gradients
Apply transformations to gradients:Color Interpolation
By default, gradients interpolate in unpremultiplied space. Setflags={1} to interpolate in premultiplied space:
Advanced Examples
Rainbow Circle
Metallic Effect
Spotlight Effect
See Also
- Color Shaders - Solid colors and blending
- Image Shaders - Using images as shaders
- Perlin Noise - Procedural noise shaders
- Transformations - Transform matrices