riuseigi://lab← Writing

How the dot avatar ripples

#webgl#this-site

The hero on the home page is my avatar, redrawn as a mosaic of 2 px dots. Behind him sits a faint grid of bigger dots, and when you move the cursor, waves roll through that grid.

A ring, not a list

The shader can't loop over an unbounded list, so the page only remembers the last 16 places the cursor stirred the dots. Each one is four numbers: where it happened, when, and how hard. They are packed flat into a Float32Array, which is exactly the shape the shader's vec4 uPoints[16] reads.

export const MAX_POINTS = 16;
export const LIFE = 1.2; // seconds a ripple takes to settle
 
/** Adds a point, overwriting the oldest once the ring is full. */
export function pushPoint(r: Ripples, x: number, y: number, t: number, strength: number) {
  r.data.set([x, y, t, strength], r.next * 4);
  r.next = (r.next + 1) % MAX_POINTS;
}

A new point overwrites the oldest one. Because a ripple fades after 1.2 seconds and points are pushed no faster than one every 75 ms, the ring always holds a full lifetime of waves and never drops one that is still moving.

Knowing when to stop

When every point is older than its lifetime, nothing on screen is moving, and the renderer can stop drawing frames until the cursor moves again. That check is one small loop, and it is why the hero costs almost nothing while you read.

Why the avatar never wobbles

The ripples only move the grid. My avatar stays still on top, fully opaque, so his face (and the expressions you get by poking him) stays readable.