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.
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 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.
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).
- SqueezeThe muscle ring closes the bell and pushes.
- RecoilElastic tissue springs the bell open. No muscle.
- CoastThe stroke's leftover swirl pushes it again. No muscle.
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, , running from 0 to 1 over a stroke, and make everything else a function of it.
The bell. A short power stroke takes fraction of the cycle, and the long recovery takes the rest. Here is how squeezed the bell is, from 0 (open) to 1 (closed):
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 .
// 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 , and the arm is built by walking along those directions one equal step at a time:
Because every step has the same length, the arm keeps length 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;
Where my model is wrong
I can check this model against the real animal, so I should.
Integrating over one stroke gives the share of distance that comes from the recovery shoulder:
With the values on my homepage (), 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.
of each stroke’s distance comes from the coast.
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.
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 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.
- Water light. Capped at 1,048,576 pixels and redrawn 24 times a second
- Anatomy. Ordinary curves, drawn into a hidden canvas at a fraction of screen size
- Sampling. Each character reads one 2×2 block of that canvas
- Glyphs. Every character on screen, painted in one WebGL draw
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.
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.
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.
Sources
- Gemmell, B. J. et al. (2013). Passive energy recapture in jellyfish contributes to propulsive advantage over other metazoans. PNAS 110(44).
- Gemmell, B. J., Colin, S. P., Costello, J. H. & Dabiri, J. O. (2015). Suction-based propulsion as a basis for efficient animal swimming. Nature Communications 6, 8790.
- Colin, S. P. et al. (2012). Biomimetic and live medusae reveal the mechanistic advantages of a flexible bell margin. PLoS ONE 7(11).
- Yang, P. J., Lemons, M. & Hu, D. L. (2018). Rowing jellyfish contract to maintain neutral buoyancy. Theoretical & Applied Mechanics Letters 8.
- Footage: C. Reinboth, Fortbewegung einer Ohrenqualle, CC BY 4.0. E. Polk, Aurelia sp. swimming - MBA, CC BY-SA 4.0.