Canvas & 2DPen ink that tidies into shapes
Freehand ink from a mouse, a finger or a pen.
What it costs a frame
- GPU
- not used
- CPU, median
- 0.21 ms
- CPU, 95th pct
- 0.42 ms
- Draw calls
- 0
- Weight
- Light
Measured 13 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.14–0.21 ms). What ran: Measured writing by itself: the seven sample strokes drawn point by point, recognised and morphed into shapes, then the sheet cleared and drawn again. Idle, nothing is drawn. Phones: tiers are being measured next.
| Machine | GPU ms | CPU ms | CPU p95 |
|---|---|---|---|
| RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool | not timed | 0.21 | 0.42 |
| apple · Apple A19 Proin a browser tab · 16 November 2026 | not timed | 0.30 | 0.46 |
| Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026 | not timed | 0.24 | 0.55 |
Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.
What it needs
- Renders with
- Canvas 2DA 2D canvas: every current browser.
- Your browser
- Runs hereNo WebGPU needed
- Depends on
- NothingNo other packages
What it’s for
- A pen or highlighter on a whiteboard or canvas app
- Sketching diagrams that come out clean
- Annotating screenshots, slides or documents
- Signatures and handwritten notes
- A stylus on a tablet with the palm resting on the screen
- Ink saved or exported as SVG
Pitfalls, in brief
- Read pressure only from pens (
pointerType === "pen"): a mouse reports 0.5 while pressed and many touch screens 0 or 1, so pressure from them gives ink that is half or doubly wide. pressureOf does this. - Recognise the whole smoothed path (
rawfrom InkRecorder.end), not the simplified points: simplification is tuned to look the same, and drops the very wobble that tells a circle from a polygon. - Smoothing trails the pointer: with a lag of 0.45 the last smoothed point stops short of where the pen lifted.
- Fill a stroke once, as one outline (traceInk traces every capsule clockwise, so the non-zero rule joins them).
- Simplify in screen pixels (
tolerance / zoom): a fixed tolerance in world units throws detail away when zoomed in and keeps too much when zoomed out.
6 more in brief
- Use getCoalescedEvents for pens: a pen samples at 120–240 Hz but pointermove fires once a frame, and the rest are only in the coalesced list.
- Recognition is deliberately conservative, and should stay so: a wrong guess that turns writing into a box is far worse than a shape left as ink.
- Check a new stroke against nearby lines for an arrow head before recognising it on its own: a small "V" alone can pass for a tiny arrow.
- Once a pen has touched the sheet, ignore touch pointers for ink: a palm resting on a tablet otherwise draws.
- End the stroke on lostpointercapture too: an up the canvas never sees otherwise leaves the pointer down, so its hover moves ink and its next press is taken for a second finger.
- Set
touch-action: noneon the canvas, or a finger’s stroke scrolls the page and the pointer is cancelled mid-stroke.
Where it comes from
From SpaciousPro. Fully custom code.
Ramer–Douglas–Peucker line simplification (Ramer 1972; Douglas & Peucker 1973): simplifyStroke, and the corner and turn finding in the recogniser
Lehmer’s multiplicative generator (the Park–Miller “minimal standard”, 1988): the seeded wobble of the demo’s sample strokes and of the tests’ hand-drawn paths, as in the source tests


