Menu
Docs menu

Gradient

A linear, radial, conic or wave gradient drawn as a dither.

Preview

Expanded preview

Installation

Terminal window
pnpm add astro-dither

Or copy the source into your project:

Terminal window
npx astro-dither add effect

Usage

src/pages/index.astro
---
import { DitherEffect } from "astro-dither";
---
<DitherEffect effect="gradient" palette={["#000000", "#00b2ff", "#d6efff"]} />

Four modes under one prop: linear sweeps along an angle, radial grows from a point, conic spins around it, and wave strips the screen horizontally. The ramp itself is two stops, from and to, blended through the palette.

The props group like this:

Shape: mode, angle, cx, cy, radius. Ramp: from and to, blended through palette. Motion: speed rotates linear and conic modes.

Examples

Conic spin

mode 2 turns the ramp around its centre, and speed keeps it turning.

Expanded preview

Horizontal wave

mode 3 drops the ramp for soft horizontal bands that drift.

Expanded preview

Props

PropTypeDefaultDescription
modenumber10 linear, 1 radial, 2 conic, 3 wave. 0 to 3.
anglenumber180Ramp direction in degrees (linear and conic). 0 to 360.
cxnumber0.5Centre x, 0 to 1. 0 to 1.
cynumber0Centre y, 0 to 1. 0 to 1.
radiusnumber1.05Radial reach. 0.1 to 2.
fromnumber1Ramp start stop. 0 to 1.
tonumber0Ramp end stop. 0 to 1.
palettestring[]the effect's2 to 8 colours, paper first, brightest last. transparent works.
cellnumber2Size of one dither cell in CSS pixels. Rounded to whole device pixels so cells stay even.
matrix2 | 4 | 8 | "noise"8The Bayer threshold size, or noise for a random look.
speednumber1Playback speed. 0 draws one still frame.
stillTimenumberthe effect'sThe moment drawn when motion is off or reduced, in seconds.
levelsnumber0 (all)Tones the field snaps to before dithering. Low values give hard, posterised steps.
bloomnumber0Bloom around lit cells, 0 to 1. Set a positive prop to create the overlay before overriding it with CSS --dither-bloom.
bloomRadiusnumber10Bloom blur in CSS pixels. CSS --dither-bloom-radius overrides it.
classstringundefinedClasses on the surface element, for size and position.

Notes

  • Decorative and aria-hidden. Put real text on top of it, not inside it.
  • With reduced motion it draws one still frame at 0s and stops.
  • It pauses when scrolled out of view or when the tab is hidden.
  • It shares one WebGL context with every other ordered effect on the page.