Teaching an ASCII jellyfish to swim

Srujan Ponnapalli, October 2026

The jellyfish at the top of my homepage is made of letters. Look closely and the bell is a cloud of x, % and #, the arms are trails of + and :, and the light around it is a blur of the same characters. Step back and it swims.

Making it look good was the easy part. The harder problems were making it feel alive and making it cheap enough to leave running. This is the story of both, told in the order I got it wrong.

Why a jellyfish

The jellyfish wasn't the only scene I tried for the homepage. There was a branching watershed, a constellation that morphs between a map and a molecule, and a storm sea with breaking whitecaps. Of everything I tried, the jellyfish was the one I couldn't stop looking at.

The other candidates: a watershed, a constellation, a storm sea.

10 mThe first one

The first jellyfish worked. It pulsed, it rose, its tentacles waved. And it felt robotic. If I had to describe it in four words: stiff, inorganic, too rhythmic, too fast.

The first version, October 27. Everything happens on the beat.

The code explains why. The bell's pulse was a simple clock: squeeze for 35% of the cycle, relax for 45%, rest for 20%, then start over.

// scene-geometry.ts: the original pulse
const pulsePeriod = 1.45 + pseudoRand(index * 13.7 + 2.3) * 0.65;
const contract = cycle < 0.35 ? Math.sin((cycle / 0.35) * Math.PI) : 0;
const expand = (cycle >= 0.35 && cycle < 0.80) ? Math.sin(((cycle - 0.35) / 0.45) * Math.PI) : 0;

Nothing is wrong with that clock on its own. The problem was what listened to it. The tentacles waved on a separate clock that ignored the bell entirely, at one tempo shared by every jellyfish on screen, so the whole school swayed like a screensaver. The oral arms took their length straight from the bell's height:

// draw-jellyfish.ts: arm length in the baseline study
const armLength = (study === "baseline" ? bellHeight : r * 1.2) * (2.2 + Math.sin(arm * 1.8) * 0.4) * (form?.armLength ?? 1);

When the bell squeezed, its height went from 0.65 to 1.00 of its radius, so the arms grew 54% longer on every stroke and shrank back on every release. No animal does that. My eye didn't know why it felt fake, but it could tell.

40 mA real one

So I went and watched a real one.

A moon jelly at GEOMAR Aquarium Kiel, tracked frame by frame. Amber while the bell squeezes, cyan while it recoils. Footage: C. Reinboth, CC BY 4.0.

I tracked its bell in every frame of a short aquarium clip. Its pulse period came out at 1.47 seconds. My "too fast" first version beat every 1.45 to 2.1 seconds. They're the same speed.

So speed was never the problem; the real animal is just as quick. The difference is that its parts don't move together. Its bell squeezes, and only then does the rim follow, the body coast, and the tentacles catch up, each a beat late. Mine did everything at once.

How a jellyfish actually swims

Most people picture a jellyfish as a squirt gun: squeeze the bell, push water out, move forward. That's about half of it.

A moon jellyfish (Aurelia aurita) has a broad, shallow bell lined with a ring of muscle. The muscle squeezes, and the bell narrows and pushes the animal forward. Then the muscle lets go, and the bell springs back open by itself, because its jelly-like tissue is elastic. As it reopens, the swirl of water left behind by the stroke slips under the bell and pushes it a second time. The animal keeps moving while its muscles rest.

Researchers call this passive energy recapture. In Gemmell and colleagues' measurements it carried moon jellies about 30% further per stroke, for free (Gemmell et al., 2013). A later study found that rowing jellyfish also pull themselves forward with low pressure in front of the bell, not just push from behind (Gemmell et al., 2015). The bell's flexible edge bends on its own timing, and that flap matters for thrust (Colin et al., 2012). Each species keeps its own steady beat, about 0.75 Hz for moon jellies, a little slower in bigger animals (Yang, Lemons & Hu, 2018).

  1. SqueezeThe muscle ring closes the bell and pushes.
  2. RecoilElastic tissue springs the bell open. No muscle.
  3. CoastThe stroke's leftover swirl pushes it again. No muscle.
One stroke at half speed. Amber is muscle; cyan is elastic tissue and water.

I didn't take any numbers from these papers. What I took was the idea that every part of the animal answers to the same stroke, each at its own delay.

80 mOne clock for everything

The fix was to give each jellyfish one phase, φ\varphi, running from 0 to 1 over a stroke, and make everything else a function of it.

φ = 0.10, squeezing
One phase drives the bell and the speed. Drag it, or let it run.

The bell. A short power stroke takes fraction pp of the cycle, and the long recovery takes the rest. Here ss is how squeezed the bell is, from 0 (open) to 1 (closed):

s(φ)={12(1−cos⁡πφp)φ<p12(1+cos⁡π(φ−p)1−p)φ≥ps(\varphi) = \begin{cases} \tfrac12\left(1 - \cos\dfrac{\pi\varphi}{p}\right) & \varphi < p \\[1.2em] \tfrac12\left(1 + \cos\dfrac{\pi(\varphi - p)}{1-p}\right) & \varphi \ge p \end{cases}

The rise. Forward speed follows the same stroke: a strong push while squeezing, then a smaller shoulder of speed while the bell reopens. That shoulder is my stand-in for the free push from recaptured water. Its size is ρ\rho.

e(φ)={sin⁡2πφpφ<pρ sin⁡2π(φ−p)1−pφ≥pe(\varphi) = \begin{cases} \sin^2\dfrac{\pi\varphi}{p} & \varphi < p \\[1.2em] \rho\,\sin^2\dfrac{\pi(\varphi - p)}{1-p} & \varphi \ge p \end{cases}
// jellyfish-motion.ts
export function studyPropulsion(time: number, index: number, mode: JellyfishStudy = "tidal-drift") {
  const { phase, power, recovery } = stroke(time, index, mode);
  return phase < power ? Math.sin(Math.PI * phase / power) ** 2
    : recovery * Math.sin(Math.PI * (phase - power) / (1 - power)) ** 2;
}

The strands. Each point along a tentacle reads the bell's squeeze from a moment ago, and the further down the tentacle, the older the moment. The squeeze travels from root to tip like a wave down a rope, though nothing is being simulated: each point just reads the bell's clock a little late.

Arms that don't stretch

To stop the arms from telescoping, I stopped moving their points sideways and started bending them. Each small segment points in a direction θ\theta, and the arm is built by walking along those directions one equal step at a time:

X(q,t)=r(t)+L∫0q[sin⁡θ(u,t), cos⁡θ(u,t)] duX(q,t) = r(t) + L \int_0^q \big[\sin\theta(u,t),\ \cos\theta(u,t)\big]\,du

Because every step has the same length, the arm keeps length LL however much it curls.

// jellyfish-motion.ts: studyStrand
points[step].x = previous.x + Math.sin(angle) * length / count;
points[step].y = previous.y + Math.cos(angle) * length / count;
Arm length 100% of rest
Same jellyfish, two arm rules. Watch the readout.

Where my model is wrong

I can check this model against the real animal, so I should.

Integrating e(φ)e(\varphi) over one stroke gives the share of distance that comes from the recovery shoulder:

share from recovery=ρ(1−p)p+ρ(1−p)\text{share from recovery} = \frac{\rho(1-p)}{p + \rho(1-p)}

With the values on my homepage (p=ρ=0.24p = \rho = 0.24), that's about 43%. The real number for moon jellies is about 30%. My jellyfish coasts too much. I tuned it by eye, and my eye liked the glide.

pushcoast
The recovery shoulder, and the share of distance it accounts for.

The bell's timing doesn't match either. In the Kiel clip, the real bell spends longer squeezing than mine. The best fit puts its power stroke at about 44% of the cycle, against the 24% my homepage uses, and even the best fit misses the real curve by more than the margin I set in advance. That's one animal in one six-second clip, filmed from an angle, so I'm not calibrating anything from it. But I'm not hiding it either.

200 mOut of the screen

Once it swam right, I wanted it to be beautiful. The image in my head was a surrealist one: a computer artifact pulled out of a screen and dropped into a real ocean. The jellyfish should stay unmistakably made of characters, while everything around it behaves like water.

The same school, before and after the light.

So the letters got light. Each jellyfish's amber core became a light source for the water around it. The school split into three depth planes: near ones large and sharp, far ones small, dim and soft. Bubbles rise in irregular columns. The jellyfish don't appear all at once on load. They surface in three waves, nearest first.

Paths not taken

I tried to push the realism further, and it made things worse.

Tidal Drift, Medusa Forms, and Luminous Shoal, the one that shipped.

Tidal Drift gave each jellyfish a body with momentum. It steered toward a heading, drifted in a slow current, and turned before its path caught up. It was more biologically honest. It was also less beautiful. At a certain point, artistic vision matters more than accuracy, and steering took away from the calm I wanted.

Medusa Forms added two body types: a flat, wide Veil and a tall Crown with eight heavy arms. Each looked good on its own. Together they were too much variety for a hero that should read in one glance.

Luminous Shoal is what shipped: the original adults, untouched, plus one or two small Crown companions in lavender and peach. Enough difference to reward a second look, not enough to compete with the headline.

1,000 mThe bare bones

Making the scene beautiful took some effort. Breaking it back down to its bare bones, to find out what each piece actually cost, took ten times that. I didn't expect performance to be the main fight, but it was.

  1. Water light. Capped at 1,048,576 pixels and redrawn 24 times a second
  2. Anatomy. Ordinary curves, drawn into a hidden canvas at a fraction of screen size
  3. Sampling. Each character reads one 2×2 block of that canvas
  4. Glyphs. Every character on screen, painted in one WebGL draw
One frame, taken apart into the four layers that draw it.

Here is what draws one frame. The anatomy (bell, arms, tentacles) is drawn as ordinary curves into a hidden canvas at a fraction of screen size. Each character on screen reads a 2×2 block of that canvas. The opacity picks the glyph from .:+*x%#@, the color picks the tint. Then the glyphs are painted, the water is lit, and three depth planes are blurred and stacked. That happens sixty times a second.

Every step of that has a price, and most of the work was deciding which prices to pay.

The ledger

What I gave up What I got Worth it?
Painting each glyph separately All glyphs in one WebGL draw Yes
Full-resolution water Water capped at 1,048,576 pixels. It's a soft gradient, so nobody can see the difference Yes
Full-resolution blur on distant planes Blurred planes capped at 3,145,728 pixels, even on a 2560×1440 display Yes
Recalculating every tentacle point every frame Each jellyfish's squeeze sampled 32 times and shared, removing 5,082 allocations per frame Yes
Redrawing the water at full frame rate The slow water field redraws 24 times a second while the jellyfish run at 60 Yes
Drawing jellyfish nobody can see Each depth plane stops drawing entirely once it has faded out on scroll Yes
A cheaper single layer at rest Three depth planes kept all the time, so nothing pops when scrolling starts Yes. It costs more, and continuity was the point.

Measured in my development browser at about 1280×720, steady render work fell from roughly 12.8 ms to about 10 ms per frame. Mid-scroll, the slowest frames fell from 15.8 ms to 9.9 ms. Those are timings of my own code, not delivered frame rates on your phone, and I haven't profiled a real phone yet.

What failed

My first fade-in faded the curves before converting them to characters. As the opacity rose, the glyph choice kept changing, and the jellyfish shimmered through faint, unstable previews of itself. The fix was to draw each layer at full strength, convert it, then fade the finished pixels.

The same fade-in, done in the wrong order and the right one.

Safari ignores the canvas blur filter entirely, so the blurred depth planes came out sharp. That needed its own fallback: shrink, smooth and scale back up.

These fixes didn't change how the jellyfish looks in a screenshot. They're why it still looks that way after a minute of scrolling on a laptop fan.

SurfacingWhat this toy gets wrong

Here's what the model leaves out.

  • There is no water. No vortices, no pressure. The recovery shoulder is drawn, not computed.
  • It coasts too much: about 43% of each stroke's distance against about 30% in a real moon jelly.
  • Its timing is measured in screen pixels and screen seconds. A period that happens to match a real one proves nothing.
  • The tentacles follow a delayed curve, not a material. They look like they trail through water, but nothing is being dragged.
  • One body plan stands in for many very different animals.

I wanted an impression of a jellyfish built from what real ones do, and that's what this is. A simulation would be a different, much bigger project.

0 mTouch one

Click or tap a bell.

Each jellyfish has its own clock now, and every part of it answers to that clock a little late, the way the real ones do. Go ahead and startle one.


Lab drawer

Not everything got a chapter. There were six depth studies before the water settled (attenuation, glyph scale, foreground, surface light, no tint, and the light and drift that shipped), a study of bubble columns, and smaller, tasteful visual tweaks to the bells and arms along the way.

Sources