# Tile Wave

> An isometric field of extruded tiles rising and falling in slow, overlapping waves, crests glowing, with a ripple wherever the cursor passes.

Category: Backgrounds · Free · Updated 2026-11-10 · Live demo: https://www.motionkitui.com/components/tile-wave

## When to use it

Infrastructure, data and Web3 heroes, gaming and architecture sites, and anywhere a structured, dimensional backdrop beats a flat one.

## How it works

Tiles sit on a square grid drawn in isometric projection, where a tile's screen position comes from the difference and sum of its grid coordinates. Each tile's height is a sum of waves (rings from the centre and two travelling across), and it's drawn as a block with a lit top and two shaded sides, back to front so nearer blocks cover farther ones. Crests are tinted towards the second colour. Pointer movement is mapped back to grid coordinates and drops a ripple there that spreads and fades.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/tile-wave.json
```

Or copy `components/motionkit/tile-wave.tsx` below. Requires react and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `colors` | `[string, string]` | `["#1B2A33", "#7FD6E0"]` | Tiles at rest and at a crest. |
| `background` | `string` | `"#0A0D12"` | Colour behind the field. |
| `size` | `number` | `18` | Tiles along each side. |
| `amplitude` | `number` | `1` | Wave height, 0 to 2. |
| `speed` | `number` | `1` | Wave speed. 0 holds it still. |
| `interactive` | `boolean` | `true` | Let the pointer send a ripple across. |
| `children` | `ReactNode` |  | Your content, layered above. |

## Accessibility

- **Keyboard: Not applicable.** Decorative, nothing to focus.
- **Screen readers: Pass.** The effect is hidden from assistive tech; only your content is read.
- **Reduced motion: Pass.** With reduced motion on, the field is drawn once and holds still. It also stops animating off screen.
- **Colour contrast: Partial.** White text measures 19.5:1 on the background but only 1.7:1 on a glowing crest, so place headings in the faded band at the top, as the demo does.

## Source

```tsx
"use client";

import { useEffect, useRef, type ReactNode } from "react";

type TileWaveProps = {
  children?: ReactNode;
  /** Colour of the tiles at rest, and at the crest of a wave. */
  colors?: [low: string, high: string];
  /** Background behind the field. */
  background?: string;
  /** Tiles along each side of the field. */
  size?: number;
  /** Wave speed. 0 holds the field still. */
  speed?: number;
  /** Height of the waves, 0 to 2. */
  amplitude?: number;
  /** Let the pointer drop a ripple into the field. */
  interactive?: boolean;
  className?: string;
};

const rgb = (hex: string) => {
  const value = parseInt(hex.replace("#", "").padEnd(6, "0").slice(0, 6), 16);
  return [(value >> 16) & 255, (value >> 8) & 255, value & 255];
};

/**
 * An isometric field of square tiles that rise and fall in slow, overlapping waves, each one an extruded block
 * with a lit top and shaded sides. Crests glow towards a second colour, and the pointer sends a ripple across.
 */
export function TileWave({
  children,
  colors = ["#1B2A33", "#7FD6E0"],
  background = "#0A0D12",
  size = 18,
  speed = 1,
  amplitude = 1,
  interactive = true,
  className = "",
}: TileWaveProps) {
  const canvasRef = useRef<HTMLCanvasElement>(null);

  useEffect(() => {
    const canvas = canvasRef.current;
    const area = canvas?.parentElement;
    const context = canvas?.getContext("2d");
    if (!canvas || !area || !context) return;
    const still = speed === 0 || window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    const [low, high] = colors.map(rgb);
    const n = Math.max(6, Math.round(size));

    let width = 0;
    let height = 0;
    let ratio = 1;
    let frame = 0;
    let visible = true;
    let last = 0;
    let time = 3;
    // ripples dropped by the pointer: where, and when
    const ripples: { gx: number; gy: number; born: number }[] = [];

    const mix = (amount: number, light: number) => {
      const t = Math.max(0, Math.min(1, amount));
      const [r, g, b] = low.map((channel, index) => (channel + (high[index] - channel) * t) * light);
      return `rgb(${Math.round(Math.min(255, r))}, ${Math.round(Math.min(255, g))}, ${Math.round(Math.min(255, b))})`;
    };

    function resize() {
      const rect = canvas!.getBoundingClientRect();
      ratio = Math.min(window.devicePixelRatio || 1, 2);
      width = rect.width;
      height = rect.height;
      canvas!.width = Math.max(1, Math.round(width * ratio));
      canvas!.height = Math.max(1, Math.round(height * ratio));
    }

    // the grid in isometric space: a tile's corner lands at (gx - gy, gx + gy) halved, scaled to fill the area
    const layout = () => {
      const tile = Math.max(width / (n * 1.05), (height * 1.6) / n);
      return { tile, ox: width / 2, oy: height / 2 - (n * tile) / 4 };
    };

    function heightAt(gx: number, gy: number) {
      const cx = gx - n / 2;
      const cy = gy - n / 2;
      let h = Math.sin(Math.hypot(cx, cy) * 0.55 - time * 1.4) * 0.6 + Math.sin(cx * 0.35 + time * 0.8) * 0.3 + Math.cos(cy * 0.4 - time * 0.6) * 0.3;
      for (const ripple of ripples) {
        const age = time - ripple.born;
        const d = Math.hypot(gx - ripple.gx, gy - ripple.gy);
        h += Math.sin((d - age * 6) * 1.1) * Math.exp(-Math.abs(d - age * 6) * 0.4) * Math.exp(-age * 0.8) * 1.4;
      }
      return h * amplitude;
    }

    function draw() {
      const c = context!;
      c.setTransform(ratio, 0, 0, ratio, 0, 0);
      c.clearRect(0, 0, width, height);
      const { tile, ox, oy } = layout();
      const half = tile / 2;
      const quarter = tile / 4;
      const lift = tile * 0.45;
      // back to front, so nearer blocks cover the ones behind
      for (let sum = 0; sum < n * 2 - 1; sum++) {
        for (let gx = 0; gx < n; gx++) {
          const gy = sum - gx;
          if (gy < 0 || gy >= n) continue;
          const h = heightAt(gx, gy);
          const x = ox + (gx - gy) * half;
          const y = oy + (gx + gy) * quarter - h * lift;
          const base = tile * 0.9;
          const glow = (h / Math.max(0.01, amplitude) + 1) / 2;
          // left side, right side, then the lit top
          c.fillStyle = mix(glow * 0.8, 0.55);
          c.beginPath();
          c.moveTo(x - half, y);
          c.lineTo(x, y + quarter);
          c.lineTo(x, y + quarter + base);
          c.lineTo(x - half, y + base);
          c.fill();
          c.fillStyle = mix(glow * 0.8, 0.38);
          c.beginPath();
          c.moveTo(x + half, y);
          c.lineTo(x, y + quarter);
          c.lineTo(x, y + quarter + base);
          c.lineTo(x + half, y + base);
          c.fill();
          c.fillStyle = mix(glow, 0.85 + glow * 0.3);
          c.beginPath();
          c.moveTo(x, y - quarter);
          c.lineTo(x + half, y);
          c.lineTo(x, y + quarter);
          c.lineTo(x - half, y);
          c.fill();
        }
      }
    }

    function loop(now: number) {
      const dt = last ? Math.min(0.05, (now - last) / 1000) : 0;
      last = now;
      time += dt * speed;
      while (ripples.length && time - ripples[0].born > 4) ripples.shift();
      draw();
      frame = visible ? requestAnimationFrame(loop) : 0;
      if (!frame) last = 0;
    }

    resize();
    draw();
    if (!still) frame = requestAnimationFrame(loop);
    const resizeObserver = new ResizeObserver(() => {
      resize();
      draw();
    });
    resizeObserver.observe(canvas);
    const visibilityObserver = new IntersectionObserver(([entry]) => {
      visible = entry.isIntersecting;
      if (visible && !frame && !still) frame = requestAnimationFrame(loop);
    });
    visibilityObserver.observe(canvas);

    // turn a point on screen back into grid coordinates (the inverse of the isometric layout)
    let lastDrop = 0;
    function move(event: PointerEvent) {
      if (!interactive || still || event.pointerType === "touch") return;
      if (time - lastDrop < 0.35) return;
      lastDrop = time;
      const rect = canvas!.getBoundingClientRect();
      const { tile, ox, oy } = layout();
      const a = (event.clientX - rect.left - ox) / (tile / 2);
      const b = (event.clientY - rect.top - oy) / (tile / 4);
      ripples.push({ gx: (a + b) / 2, gy: (b - a) / 2, born: time });
      if (ripples.length > 6) ripples.shift();
    }
    area.addEventListener("pointermove", move);

    return () => {
      cancelAnimationFrame(frame);
      resizeObserver.disconnect();
      visibilityObserver.disconnect();
      area.removeEventListener("pointermove", move);
    };
    // the colours are compared by value, so a new array with the same colours doesn't restart it
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [colors.join(), size, speed, amplitude, interactive]);

  return (
    <div className={`relative isolate overflow-hidden ${className}`} style={{ background }}>
      <canvas ref={canvasRef} aria-hidden className="pointer-events-none absolute inset-0 -z-10 size-full" />
      {/* fades the far edge of the field into the background */}
      <div aria-hidden className="pointer-events-none absolute inset-0 -z-10" style={{ background: `linear-gradient(to bottom, ${background} 0%, transparent 35%, transparent 75%, ${background} 100%)` }} />
      {children}
    </div>
  );
}
```
