|

Pen pressure

On this page, we study how pen pressure alone shapes a single stroke of one color.

The demo draws the basic rounded stroke in gray on white, so the only thing to look at is how pen pressure becomes width. DrawInput records a pressure on every drawn point (a mouse records zero), and a mapping turns it into the width along the stroke. Lengths in the controls and readouts are CSS pixels: the canvas draws at a fixed scale, so resizing the window crops or reveals paper rather than rescaling the drawing.

Before the mapping, the pressure passes through a dead zone and a response curve. The slightest touch of a pen never reports zero, so pressure below the threshold counts as the lightest touch and the remainder is stretched back to the full range. The result is then raised to an exponent. Raw tablet pressure feels front-loaded (a light touch already reports a substantial value), so an exponent above 1 spreads the low end out and makes light strokes easier to hold; below 1 compresses it. Both demos expose these as Threshold and Curve.

The mapping is a ratio around the set width: middle pressure draws the width as set, a light touch shrinks it and a heavy press grows it by the same factor, up to the scale at either end. A mouse, which records no pressure, draws the set width. After the mapping, the width passes a slope limit: it cannot rise or fall faster than the limit per unit of length, clamped in a forward and a backward pass. A hard press becomes a swell and a quick release a tapered exit instead of a cliff. At 1 the outline flares at most 45 degrees, which is also about where the stroke geometry would start to fold. Both demos expose it as Limit, and the pressure itself is smoothed by a short moving average before any of this. Pressure, width, and the limit are all parameterized by distance from the start, and the smoothing spline is local, so the drawn part holds still while the stroke grows; only a short zone at the tip reflows.

Scaled width

open full size ↗

Pressure scales the base width as a ratio: middle pressure draws the base, a light touch down to the base over the scale, full pressure up to the base times the scale.