Build log · Games
How I built Ink Crane
Fly a crane over an endless shan-shui-inf ink landscape rendered in a Web Worker

1.Why I built it
Lingdong Huang's shan-shui-inf generates an endless Chinese landscape painting in the browser. I wanted to fly through one. Ink Crane uses his generator (MIT licensed) for the scenery and puts a small canvas game on top: a red-crowned crane, lanterns to collect, ink storms and hawks to avoid.
The goal ties back to the painting tradition. Seals carry characters from Liu Zongyuan's poem River Snow (江雪), and catching them in order completes the poem line by line.
2.How it works
The landscape generator runs in a Web Worker
shan-shui-inf was written as a single web page that builds SVG strings. I pulled out the generator, stubbed the window and document it expects inside a worker, and replaced Math.random with its seeded PRNG so a seed gives the same scroll every time. The worker asks the generator's chunk loader for one more column at a time until the landscape reaches 600 units past the panel it is drawing, since chunks anchored to the right can spill about 500 units left.
Each chunk's SVG is parsed once with a regex into draw ops: polylines become Float32Array point lists with fill, stroke and width, and text elements keep their translate and rotate. The chunk's x-extent is recorded so panels can find their chunks quickly, and chunks that have scrolled off to the left are pruned.
Panels rasterised off the main thread
The scroll is cut into 1024-unit-wide panels. For each one the worker replays the parsed ops into an OffscreenCanvas at the current raster scale and sends back the result with transferToImageBitmap, so the game thread only ever draws finished bitmaps. Browsers without OffscreenCanvas in workers get the panel's SVG instead and let the main thread rasterise it.
The game keeps panels two widths ahead of the camera. It drops panels that have passed off the left edge, or that were painted at a scale more than 20% off after a resize. If the next panel isn't ready, the camera slows to 12% speed and shows a "brushing" note, so you never fly over blank paper.
Paper and sound
The rice-paper background is a 256 px tile of smooth value noise plus per-pixel grain. It is mirrored at the half-way point in both axes so the pattern repeats with no visible seam.
The sound has two parts. One is a looped white-noise buffer through a band-pass filter at 500 Hz whose gain follows flight speed, which reads as wind. The other is plucked notes for lanterns and seals: a triangle wave with a short pitch drop plus a quiet sine an octave up, on a D major pentatonic scale.
Flight and layout
The crane eases toward a target velocity, from the keys or toward the pointer. With no input it drifts and sinks slowly, as if gliding. Wing flap speed follows what you are doing, so climbing flaps fastest.
The world is 720 units tall, and the view is never narrower than 640 units. That stops portrait phones from showing only a sliver of scroll with no time to react. When the height doesn't fill the screen, the painting is letterboxed and framed with mounted-scroll edges.
3.Try it
Arrow keys or WASD to fly, or point and drag to steer; on touch, steering is relative to where your finger lands.


