UICraft / Craft
CanvasASCII wave field

How ASCII wave field works

Turn value noise into drifting ASCII clouds—no particles, no physics, just a scalar field remapped every frame.

Demo
Animated ASCII characters forming drifting wave clouds on a black background.

How it works

This is not a physics simulation. Nothing has mass, velocity, or collision. We paint a grid of characters. The character in each cell is chosen from a number between 0 and 1. Changing that number over time makes the clouds appear to drift.

Step 1. Start with a canvas

A <canvas> is a blank bitmap. The browser will not lay out text inside it—you paint with the Canvas 2D API. Size the parent so the canvas has a width and height to measure.

Mark the canvas aria-hidden when it is decorative. Put the meaning in a nearby screen-reader sentence.

<div className="relative h-72 overflow-hidden bg-black">
  <canvas ref={canvasRef} className="block size-full" aria-hidden="true" />
  <span className="sr-only">Animated ASCII wave field.</span>
</div>

What you see: a black rectangle. Nothing is drawn yet.

Step 2. Draw a lattice of dashes

Stage 01Lattice

Measure the canvas with getBoundingClientRect. Multiply by devicePixelRatio (capped at 2) so the bitmap stays sharp. setTransform(dpr, 0, 0, dpr, 0, 0) lets later coordinates stay in CSS pixels.

Divide the surface into cells of size cell. At the center of each cell, draw a fixed - with fillText.

const cols = Math.ceil(width / cell)
const rows = Math.ceil(height / cell)
 
for (let row = 0; row < rows; row++) {
  for (let col = 0; col < cols; col++) {
    const x = (col + 0.5) * cell
    const y = (row + 0.5) * cell
    context.fillText("-", x, y)
  }
}

What you see: a regular grid of dashes. This lattice is the display. Later steps only change which glyph each cell shows.

Step 3. Hash cell coordinates

Stage 02Hash

A hash turns integer coordinates into a repeatable pseudo-random number in 0..1. Same input always gives the same output. Nearby cells are unrelated—so the field looks speckled, not smooth.

function hash(x: number, y: number) {
  let px = fract(x * 123.34)
  let py = fract(y * 456.21)
  const d = px * (px + 45.32) + py * (py + 45.32)
  px += d
  py += d
  return fract(px * py)
}

Map the hash to brightness and pick . or =.

What you see: static speckles. No soft clouds yet—hashes jump from cell to cell.

Step 4. Smooth with value noise

Stage 03Value noise

Value noise still hashes the integer lattice, but for a fractional point it blends the four surrounding corners. The blend uses a smoothstep curve f*f*(3-2*f) so the field has no hard edges.

function noise(x: number, y: number) {
  const ix = Math.floor(x)
  const iy = Math.floor(y)
  const fx = x - ix
  const fy = y - iy
  // hash the four corners, then mix with smoothstep weights
}

Sample noise at the cell’s UV position, not at the integer column index.

What you see: soft blobs. The speckles have melted into cloudy patches.

Step 5. Stack octaves with FBM

Stage 04FBM

Fractional Brownian motion (FBM) adds several noise layers. Each octave doubles the frequency (p *= 2.03) and halves the amplitude (amp *= 0.5). Large waves set the shape; small waves add detail.

function fbm(x: number, y: number) {
  let v = 0
  let amp = 0.5
  for (let i = 0; i < 4; i++) {
    v += amp * noise(x, y)
    x *= 2.03
    y *= 2.03
    amp *= 0.5
  }
  return v
}

What you see: richer clouds with fine structure inside larger ridges.

Step 6. Domain warp and time

Stage 05Domain warp

Domain warping samples FBM at coordinates that were themselves displaced by FBM. That folds the field into the long, flowing ridges you see on the landing page.

Time t advances each frame. A slow circular drift and small time offsets inside the warp make the pattern reorganize continuously. The glyphs still sit on fixed cell centers—only the sampled value changes.

function warpedField(u: number, v: number, t: number) {
  const driftX = Math.sin(t * 0.05) * 1.3
  const driftY = Math.cos(t * 0.04) * 1.3
  const q = /* fbm of uv + time */
  const r = /* fbm of uv + 3*q + drift */
  return fbm(u + 3 * r.x, v + 3 * r.y)
}

requestAnimationFrame drives the loop. When prefers-reduced-motion: reduce matches, freeze t at 0.

What you see: the clouds begin to drift and fold. Still only a few glyph kinds.

Step 7. Map the field to an ASCII ramp

Stage 06ASCII ramp

An ASCII ramp is an ordered list from empty to dense ink:

const ASCII_RAMP = [" ", ".", ":", "-", "=", "+", "*", "%", "@"]

Multiply the field value by ramp.length - 1, round to an index, and draw that glyph. Skip spaces. Square the density for alpha so = + * % @ read near-white while . and : stay soft—copy on top stays readable.

const level = Math.round(value * (ASCII_RAMP.length - 1))
const glyph = ASCII_RAMP[level]
const ridge = (level / (ASCII_RAMP.length - 1)) ** 2
context.fillStyle = ridge > 0.35 ? "#ffffff" : "#b8becc"
context.globalAlpha = 0.05 + ridge * 0.78
context.fillText(glyph, x, y)

What you see: the finished ambient field—dense white ridges of heavy glyphs, sparse soft dots between them, slowly warping over time.

Step 8. Cleanup

On unmount, cancel the animation frame and remove the resize and media-query listeners. On resize, rebuild the canvas bitmap and redraw. That keeps the effect sharp when the layout changes and prevents leaks when you leave the page.

Playground

PlaygroundCell size · Speed

Field controls

Tune the lattice and how fast the warped field drifts.