How this harbor is built

Drawn natively. Every frame is maths per character.

1. No engine. No WebGL. No 3D models.

One plain JS file draws on a 2D canvas. That is all.

2. One ray per character

Each character cell asks: what do I see first, looking through me?

3. Shapes are formulas, not meshes

A ray solves each formula to find where it touches. No triangles.

Plane. Buildings, dock, hull.
Cone. Masts, lighthouse.
Ellipsoid. Rocks.
Tapered limb. Trunks, branches.

Sea and island are height fields. Sails are curved cloth. Grass and spray are dots.

4. Big things are many small shapes

The ship is 169 shapes. The whole scene is 444. A ray still tests about one.

Each shape has a box. Nearest first, the ray stops at its first hit.

5. Light picks the character

Moon, lamps and the lighthouse beam add up. Brighter spot, denser glyph.

A shadow ray per lamp. A solid in the way means no light. Colour is the material, in 8 brightness levels.

6. Cost is the cell count, on every core

Rays per frame at the default glyph size. Bigger screen, more cells, until the cell cap holds 4K down.

On a desktop, web workers cast and draw bands of rows on the other cores. Desktops keep every row and every shadow, and never grow glyphs. Only a slow phone turns shadows off, then grows glyphs up to 1.5x.

7. How you move

You walk in 10 cm hops. Before each hop the page asks two questions.

Is there ground, and is it no more than 0.6 m above or below the last hop? Is a solid in the way between 0.3 m and 1.7 m above your feet? Each solid is an invisible box, 25 cm wider on every side. A yes to either stops you on the spot.

8. Where everything lives

In one fixed list in memory. The page loads no models and no pictures. Only the sound loops are fetched.

Each shape is a box plus a formula. The list is built once and never reloaded. The sea and the clouds are formulas, worked out for each ray. The hills and roads are formulas sampled once onto a grid. Trees and grass come from fixed seeds, so they stand in the same place on every visit.

9. See-through windows

A window is an opening that a room shares with the wall around it. A ray goes through it and carries on.

The ray carries on from where the room stands in the scene. So a room shows through its panes and the outside shows through its openings. The page looks at the far side only for the screen area of the openings. No window has its own drawing pass.

10. Zoom changes the detail

Zoom out with Ctrl/Cmd − for more, finer characters. Zoom in with + for bigger ones and a lighter load. Chromium and WebKit behave the same.

Cells at a 1440 x 900 window. From 100% to 150% the cell count stays the same: the glyphs keep to whole device pixels. The cell cap holds the zoom-out end at 76,000.

All the detail (long)

Cells per screen

One ray per cell, plus shadow rays for lit cells. Glyphs are 0.9 of the old 6.5 to 11 px range up to 2560 by 1440 CSS pixels, and taller above that, because the cell cap is 76,000 and falls with the square root of the stage area above 2560 by 1440 (about 51,000 cells at 3840 by 2160). Cells are whole device pixels. The counts assume a glyph 0.6 times as wide as tall, a 393 by 852 phone at pixel ratio 3, and desktops at pixel ratio 1. Frame time depends on the device, so it is not listed here.

ScreenCells (rays)
iPhone 15 Pro107 x 142 = 15,194
1440 x 900288 x 100 = 28,800
1920 x 1080320 x 108 = 34,560
2560 x 1440426 x 144 = 61,344
3840 x 2160 (4K)349 x 120 = 41,880

How the page spreads the work

How a phone adapts

The rest

The source on GitHub · About Crewship · Back to the harbor