An Android level built on Expo's Exact: a camera ruler that finds credit cards on its own, twenty generative zen scenes with synthesized sounds, and an APK compiled inside a Cloudflare container.
A weekend request for "a level app for my Android" turned into a camera ruler that finds credit cards on its own, twenty generative zen scenes with sounds made from scratch, and a build pipeline that compiles an APK inside a Cloudflare container.
Why build another level?
Every phone has a level somewhere, and almost all of them feel like an afterthought: a jittery bubble, a number that never settles, and nothing that tells you when you have actually got it right. I wanted the opposite. A tool that is calm, that tells you clearly when you are close, and that makes the moment you hit exactly 0.0° feel like an arrival.
The brief grew one message at a time. First a level. Then the best features from the top measuring apps. Then the "measure with a credit card" trick. Then an APK built in the cloud, a design pass, a fade to green near level, and finally: make it look like we've achieved nirvana, zen and bliss when we hit true 0.
Building on Exact
Plumb is written in Exact, Expo's framework for native apps. Most of the app lives in one declarative file,app.contract: state, derived values, actions, tasks, routes and the view tree in a single language. Device capabilities arrive as packages:@exact/motion for the gravity sensor, and@exact/media-capture and @exact/camera for the viewfinder and photos. Anything that needs real computation, like the card finder, goes in a TypeScript data module that runs in Hermes.
state zen = false
state zenStyle = 1 persist
derive err = flat ? total : edgeErr
derive nearness = min(max((6 - err) / (6 - tol), 0), 1)
task tick mount
every(50, step)
Two constraints shaped the code. Contract has no trigonometry, soatan, sin and sqrt are small hand-written approximations (a polynomial arctangent, a short Taylor series, a few Newton steps). And a data module gets roughly 100 ms of CPU per turn, which matters a great deal once you start processing images on a phone.
The math of a level
A phone at rest feels only gravity, so the gravity vector (x, y, z) says exactly how it is tilted. Plumb has two modes and picks between them on its own:
Flat, lying on a surface: the tilt is the angle between gravity and the screen's normal, shown as a bubble that drifts toward the low side.
Edge, standing against a shelf or frame: the angle is atan2(x, y), shown as a horizon line that turns against the screen.
Readings are smoothed (light, medium or heavy), a hold freezes the number when you can't see the screen, and calibration takes two readings, the second with the phone turned 180°, to cancel the sensor's own bias. You can zero against any surface and switch between degrees, percent slope and rise over run.
Fading to green
The most useful feedback turned out to be the simplest. As you approach level, the screen warms into green, gently at first and then quickly over the last degree, so you feel the target coming without reading a number. Try it:
nearness = clamp((6° - err) / (6° - tolerance)), and the green isnearness² × 0.85, reaching full green inside the tolerance.
Measuring with a credit card
Every bank card, ID and gift card shares one size: ISO/IEC 7810 ID-1,85.60 × 53.98 mm. That makes a card a free, pocketable reference. Lay one flat beside an object, photograph both from any angle, and the card's four corners tell you exactly how the camera saw that plane.
Plumb builds a homography from those corners, the 3×3 projective transform from the card's real rectangle to the four points in the photo, using Heckbert's unit-square-to-quad construction and an adjugate inverse. Running the measuring handles back through the inverse undoes the perspective, and the distance in millimetres falls out. The bundled sample photo measures a 150 mm pencil body as 15.0 cm from a steep angle, and that case is one of the app's automated tests. The one rule: the card and the object must share a plane.
Design: forward, sideways, back
The first version borrowed the restraint of the best-regarded level apps: a dark ground, one large number in a thin weight, a single line or bubble and nothing else. A second pass followed a brand board with frosted panels and decorative shapes. It looked interesting on its own and felt odd in the hand, so it went back to the first design, keeping the parts of v2 that worked: better spacing, live measuring and clearer controls. For a tool you glance at while pressing a phone against a wall, clarity beats decoration, and the delight belongs in one place only.
Zen at true zero
Hold the phone within 0.05° of level for half a second and Plumb lets go of being an instrument. The controls fade, one soft haptic lands, and the screen settles into a scene of your choosing while its sound plays. Tilt even slightly and the moment dissolves. In the gallery below each scene runs as a three-act loop: the approach (the reading easing from 2.4° to 0.0°), the arrival, and the hold. In the app, the scene starts at the arrival and holds as long as you stay level, and Settings has a live preview with a button to play each sound.
The twenty scenes, rendered live in canvas. Tap a phone to replay it with its sound, or open the gallery full screen.
Twenty specialists, one brief
The scenes went through three rounds. The first was plain CSS animation. The second rebuilt them in canvas with techniques from the generative work on Codrops (Perlin noise fields, glow through additive blending, offscreen layers) and Hakim El Hattab's particle and easing experiments. In the third round each scene got its own specialist: an AI design agent briefed as a sumi-e brush artist, a water-surface simulator, a botanical illustrator, a Turrell-style light artist, a minimalist in the line of Dieter Rams, and so on.
All twenty worked from one shared brief and rendered their own scene at six moments in the loop to check it. The brief set the bar:
Three acts that read clearly: tension, an unmistakable arrival, living stillness.
Calm and intentional. Zen means arrival, not fireworks.
Cheap enough that twenty phones animate on one page: cached offscreen layers, no per-pixel loops, no per-frame blur.
Deterministic from a seed, so a replay is the same performance.
Some results went well past the brief. The fireflies use Kuramoto coupling, the model behind real synchronous fireflies, so random blinking entrains into one shared pulse. The pond uses a damped Cauchy-Poisson dispersion model, so long ripples lead and short ones trail. The phyllotaxis scene ties the reading to the divergence angle: off level the seeds miss 137.5° and fall into restless spokes, and at zero they lock into a true sunflower.
Sounds made from nothing
Every scene has its own sound, and none are samples. They are synthesized in about 150 lines of NumPy and SciPy at build time, bundled as WAV files and played natively when zen begins.
Technique
Used for
Modal synthesis: inharmonic partials with their own decays
Temple bell, singing bowl with slow beating, chimes, celesta
Karplus-Strong plucked strings
Koto, a golden-ratio harp arpeggio, a tanpura-like drone
Generating audio at build time also keeps the source small: the whole app, twenty scenes included, travels as about 60 KB of compressed text.
Teaching it to find the card
The first ruler made you drag four corners onto the card by hand, which was fiddly on a live camera. Exact offers on-device text and barcode detection but nothing for rectangles, so Plumb got its own detector in the TypeScript data module. It is classic computer vision rather than a trained network, tuned for one shape: a rectangle near 1.586:1 once perspective is allowed for.
Shrink. About once a second the camera grabs a small frame, scaled to 256 px on the long side as a PNG. Plumb decodes the PNG itself with the runtime's DecompressionStream.
Edges in colour. Blur, then Sobel gradients from whichever colour channel changes most at each pixel. Grey misses a blue card on brown wood when both are equally bright.
Canny. Thin to one-pixel ridges and link with hysteresis, with thresholds from the image's own gradient histogram.
Hough lines. Each edge pixel votes only near its own gradient direction, which keeps the vote sharp and fast.
Pairs, then quads. Pair roughly parallel lines, combine two pairs into a quadrilateral, and score edge support along all four sides, card-like aspect, corner angles and size.
Refine. Refit each side by total least squares and intersect neighbours, so corners land within a fraction of a pixel.
Agree twice. Live detections move the corners only when two frames agree, so nothing jitters.
Here it is in your browser, the same code the app runs, on a test scene with a stray line crossing the card:
Press the button to run the detector.
On forty generated scenes (tilted, keystoned, on wood grain and gradients, with lines and blobs crossing the card) it found 38, with a median corner error of about a third of a pixel at the analysis size. One practical surprise: the data module refused the first version because a detection took about 400 ms of CPU against the 100 ms budget per turn. Every heavy loop now yields withscheduler.yield() every few thousand pixels, so detection runs in many short turns and the interface never stutters.
Shipping an APK from the cloud
The sandbox where Plumb was written could not run the Android toolchain, so the build moved to Cloudflare Containers. A small Worker backed by R2 acts as a drop box: the container fetches its build script and source from it, streams its log and status back every twenty seconds, and uploads the finished APK. The download link stays the same from build to build.
A full build takes about 27 minutes. The only way to get source into R2 was the Cloudflare API, so the compressed source travels as checksummed base64 chunks, reassembled and verified against a SHA-256 before the container starts. When the status reads done, the container is deleted.
What I learned
Delight belongs in one place. The level got better every time something was removed, and the zen moment works because everything else stays out of the way.
A shared brief scales. Twenty agents with one clear bar produced more consistent work than twenty separate requests would have.
Budgets shape algorithms. A 100 ms turn limit turned a straightforward image pipeline into a cooperative one, and the app is smoother for it.
Generate, don't ship. Synthesized sounds and procedural art keep the source small and the build reproducible.
Next: testing the card finder on many more real photos, smoothing the corners between live frames, and maybe a small trained model if the classic detector struggles in the wild.