# waves

Topographic contour lines or flowing wave lines across a hero or footer, slowly changing and shifted by scroll.

Thin lines in one color over a flat background. The contour style draws the lines of a topographic map over a relief that slowly changes shape, with every fifth line a little bolder like the index lines of a real map. The waves style draws lines that run across the element and flow sideways in soft swells, and stripes fills every other band between them. Lines keep the same width in CSS pixels wherever they run, and where they crowd together they blend into an even tone instead of flickering.

Module `backgrounds`, category Backgrounds. Import `@dioramajs/backgrounds/waves`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/backgrounds/src/waves.ts)

A trail card whose map is drawn as brown contour lines on paper, slowly changing shape, next to the route's distance, climb and time.

```html title="index.html"
<article class="wv-route">
  <div class="wv-map" aria-hidden="true" data-dio="waves" data-dio-color="#8a7a5c" data-dio-background="#efe8d8" data-dio-lines="18" data-dio-thickness="1"></div>
  <div class="wv-info">
    <p class="wv-kicker">Day hike, Zailiysky Alatau</p>
    <h2>Big Almaty Lake loop</h2>
    <dl>
      <div><dt>Distance</dt><dd>14.2 km</dd></div>
      <div><dt>Climb</dt><dd>860 m</dd></div>
      <div><dt>Time</dt><dd>5 to 6 h</dd></div>
    </dl>
    <p>Pine forest to the dam, then open ridges with the lake below. Best from June to September.</p>
  </div>
</article>
```

## Usage

Put it on: an empty decorative element behind the content, such as an aria-hidden div filling a hero or a footer; its CSS background is the look without WebGL.

`start()` registers `waves`, so the attribute alone puts it on an element.

```html
<header class="hero"><div class="hero-bg" aria-hidden="true" data-dio="waves" data-dio-color="#3b6a8f" data-dio-background="#0c1424"></div><h1>Trails for every season</h1></header>
```

In page transitions: Fades with the page transition.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'contour' \| 'waves' \| 'stripes'` | `'contour'` | contour draws the lines of a topographic map over a slowly changing relief; waves draws lines flowing across the element; stripes fills every other band between those lines. |
| `lines` | `data-dio-lines` | `number` 2 to 60 | `16` | Lines across the height of the element; more lines pack them closer. |
| `color` | `data-dio-color` | `color` | `'#3b6a8f'` | Color of the lines or stripes, any CSS color. |
| `background` | `data-dio-background` | `color` | `'#0c1424'` | Color behind the lines, any CSS color. |
| `warp` | `data-dio-warp` | `number` 0 to 1 | `0.5` | How far noise bends the lines; 0 draws straight parallel lines. |
| `speed` | `data-dio-speed` | `number` 0 to 2 | `0.3` | How fast the relief and the swells change; 0 keeps their shape. |
| `thickness` | `data-dio-thickness` | `number` 0.5 to 6 px | `1.2` | Line width in CSS pixels; stripes ignore it. |
| `scroll` | `data-dio-scroll` | `number` 0 to 1 | `0.3` | How far the lines move while the element crosses the viewport. |
| `fps` | `data-dio-fps` | `number` 0 to 60 | `30` | Most frames a second the motion draws; 0 holds it still. At most low 15, medium 24. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Shape of the noise that bends the lines. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `contour`, `waves`, `stripes`
  - `contour` draws the lines of a topographic map over a slowly changing relief.
  - `waves` draws lines flowing across the element.
  - `stripes` fills every other band between those lines.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`progress`](/docs/api/inputs#progress), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size). Draws at a steady rate while it is on screen and stops when it leaves. Up to fps frames a second while on screen, none off screen or at fps 0; scroll draws at full rate. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. A still frame: the lines neither change nor move with scroll.

Runs on every device. Nothing changes on touch screens: scroll moves the lines as usual.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { waves: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 2.1 KB the first time a page uses it. GPU: One pass over the element: four or eight reads of a small noise tile per pixel. Memory: A 128 × 128 noise tile in half floats per element, 128 KB.

- low: At most 15 frames a second.
- medium: At most 24 frames a second.

See [the quality plugin](/docs/effects/quality).

## Recipes

### Contours behind a hero

Put the lines on an empty `aria-hidden` element that fills the hero and start the app with `canvas: 'behind'`. The element’s CSS background is what visitors see before the engine draws and without WebGL, so give it the same color as `background`.

```html
<header class="hero">
  <div
    class="hero-bg"
    aria-hidden="true"
    data-dio="waves"
    data-dio-color="#2f5d50"
    data-dio-background="#0d1f1a"
  ></div>
  <h1>Trails for every season</h1>
  <a class="cta" href="/maps">Browse the maps</a>
</header>
```

```css
.hero {
  position: relative;
  isolation: isolate;
  min-height: 80vh;
}
.hero-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #0d1f1a;
}
```

```ts title="src/main.ts"
import { start } from '@dioramajs/diorama'

export const app = start({ canvas: 'behind' })
```

### Flowing lines in a fintech footer

The `waves` style runs the lines across the element in soft swells. More lines and a low `warp` give a calm, technical texture for a footer or a dashboard header, and `scroll` moves them as the footer comes into view.

```html
<footer class="site-footer">
  <div
    class="footer-bg"
    aria-hidden="true"
    data-dio="waves"
    data-dio-style="waves"
    data-dio-lines="28"
    data-dio-warp="0.4"
    data-dio-color="#24406b"
    data-dio-background="#0a1428"
    data-dio-scroll="0.6"
  ></div>
  <p>Ledger, money for teams</p>
</footer>
```

### Bold stripes for a campaign band

`stripes` fills every other band, for a loud poster look on a sale or festival page.

Orange and peach wavy bands across a wide strip, slowly changing shape.

```html title="index.html"
<div class="wv-band" aria-hidden="true" data-dio="waves" data-dio-style="stripes" data-dio-lines="9" data-dio-warp="0.7" data-dio-color="#ff7a45" data-dio-background="#ffd9b8"></div>
```

## Notes

The docs canvas sits above the page, so the examples here keep text beside the lines instead of over them. Put text over the lines with `canvas: 'behind'`, as in the first recipe.

Lines keep their width in CSS pixels wherever they run. Where they crowd together they blend into an even tone, and where the relief is flat they fade, so the picture never flickers or blots.

It draws up to `fps` frames a second while it is on screen and none off screen; scroll draws at full rate while it moves the lines. On the low tier it draws at most 15 frames a second. Set `fps` to 0 for lines that move only with scroll.

`style` and `seed` rebuild the effect when they change. The colors, line count and speeds change live.

## Related

- [blobs](/docs/effects/blobs.md): Soft blobs of brand color drifting behind a hero: merging like a lava lamp, as blurred orbs or as glossy glass drops.
- [clouds](/docs/effects/clouds.md): A sky of soft layered clouds for the time of day, daylight, a sunset or a moonlit night, drifting in the wind and parting on scroll.
- [dots](/docs/effects/dots.md): A dot grid behind a hero or in a card that answers the pointer: dots near it grow, move aside or glow, then settle back.
- [gradient](/docs/effects/gradient.md): A living background of four soft color blobs or of aurora curtains, mixed in OKLab, without banding, with a light film grain.
- [grid](/docs/effects/grid.md): A grid floor in perspective running toward the viewer under a glowing horizon: neon synthwave, a blueprint or plain thin lines.
- [stars](/docs/effects/stars.md): A night sky of twinkling stars in depth layers that lean with the pointer and the scroll, with shooting stars and a warp flight.
- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [Performance and quality](/docs/guides/performance.md)
- [Reduced motion](/docs/guides/reduced-motion.md)
