ABV Nexus home

>> Notes /

Drawing a beating heart in a text box

The figure in the About section is not a video, a canvas or WebGL. It is a <pre> element whose text is rewritten about thirty times a second. A nexus knot spins, melts into an anatomical heart, beats twice and melts back.

Shapes as distance functions

Both shapes are signed distance functions: give them a point in space and they return how far it is from the surface, negative inside.

  • The knot is a tube of radius 0.3 around a trefoil curve, sampled as 160 short segments.
  • The heart is built from parts: ellipsoids for the ventricles and atria, capsules for the aorta, pulmonary trunk and vena cava, blended with a smooth minimum so the joins look organic.

Too slow to evaluate directly

The knot function tests 160 segments per call. A frame needs thousands of rays, each taking dozens of steps, so calling it directly would never hit a usable frame rate.

Instead, both functions are sampled once into a 48 × 48 × 48 grid (about 110,000 values each) and read back with trilinear interpolation. Building the grids takes a few hundred milliseconds, so it is done in 8 ms slices between frames, only when the figure gets near the screen. Scrolling never stalls.

The morph

Blending the two grids is a straight interpolation, a + (b − a) · k. On its own that loses volume halfway: two different thin shapes average out to something thinner. A small inflation that peaks at the midpoint keeps the shape full:

mix = knot + (heart − knot) · k − 0.14 · sin(π · k)

One ray per character

Each character cell casts one ray and sphere-traces the blended grid for up to 48 steps. The surface normal comes from central differences on the same grid, and the light level picks a character from .,-~:;=!*#$@.

Turning one way only

The first version eased the knot's spin into the heart's sway by the shortest angle. That sometimes meant turning back, which looked wrong. Now the turning speed blends from fast (knot) to slow (heart), the speed is integrated over the loop, and the result is scaled to exactly one full turn. The heart faces front between its two beats, and the rotation never reverses. The knot's diagonal tumble is the same turn around a tilted axis that straightens as the heart forms.

Constraints

  • A strict content security policy: no inline scripts or styles, so every style is set from the script file.
  • Reduced-motion settings and the footer switch are respected: with motion off, the figure is a still knot.
  • On phones the figure renders at 20 frames a second and pauses when it is off screen.