Brush highlights demo
How a stroke gets made
Every highlight on this page is a real brush stroke, painted by the same engine as everything else. Scroll, and watch them land. Nothing here is an image or an SVG: each one is fresh paint, different every time you load the page.
Smoothing the hand
A finger on glass reports its position up to a hundred and twenty times a second, and every report is a little wrong. The engine first runs the points through a One-Euro filter, which irons out jitter when you move slowly and gets out of the way when you move fast, so the stroke never lags behind your finger.
Then it fits a Catmull-Rom spline through what's left and resamples it at even steps along its length. From here on, a fast flick and a slow drag have the same number of points per centimetre; only their timestamps tell them apart.
Paint, one dab at a time
There is no "stroke shape" anywhere in the code. Each mark is hundreds of tiny, slightly irregular dabs, stamped one over another with plain alpha blending. Speed decides how they're laid: a slow drag is a loaded brush, wide and dense; a fast one runs dry, narrower and full of gaps.
On top go the details a real brush leaves: bristle streaks that follow the curve, a frayed touchdown, a glossy edge, a soft cast shadow, and droplets thrown off the flanks when you're moving quickly.
Letting go
How you lift matters. Stop, and the stroke ends in a rounded blob. Lift while you're still moving and it carries on past your finger as a flicked tail, tapering and breaking into flecks.
Every random choice comes from a seed, so the same input always paints exactly the same pixels. That is what makes undo, replay and resizing possible.
Doing this on your page
Each highlight here is a small canvas behind its words, with a stroke painted along the line from code:
const paint = PaintEngine.mount(box, { input: false, scale: 0.8 });
PaintEngine.paintStroke(paint, [[0, 16], [240, 14]], {
speed: 700, color: '#FFD23F', animate: true,
});
The scale option sets the brush size, so a highlight fits its line height whatever the font.
Highlights repaint when the text reflows (resize the window to see).