Repository navigation
fix: the pencil keeps answering pressure above the neutral point (#338) - #360
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The pencil's width term was `0.65 + 0.35 * Math.min(1, pr * 2)`. The `* 2` is what puts the
neutral 0.5 at 1x, so the clamp bit at exactly neutral: every press above it drew the same
stroke to the pixel. Measured on a straight 24px stroke:
pressure 0.1 0.25 0.5 0.6 0.75 0.9 1
before 18 20 24 24 24 24 24
after 18 20 24 26 28 32 34
brush 6 12 24 30 36 44 48
A stylus writes well above 0.5, so in practice the pencil behaved as though pressure were
switched off - which is what came in from the tablet. The brush, on the same page, doubles.
Dropping the clamp only extends the curve past neutral, and that matters more than it sounds:
strokes are stored as points and re-rendered on every paint, so a change to this formula
changes artwork already drawn. Checked byte-for-byte against main - mouse, and pen at 0.1,
0.25, 0.4 and 0.5, are all identical images; only a press above neutral differs.
The alpha term keeps its clamp, and a comment now says why: it is already fully opaque at
neutral, so there is no headroom to press into, and lowering the neutral to make room would
re-render every pencil stroke ever drawn, lighter. Above neutral the pencil says pressure in
its width alone.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
difficcd
force-pushed
the
fix/pencil-pressure-clamp
branch
from
October 1, 2026 06:19
4ee2a85 to
d4f5fad
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #338 — the "pencil pressure is ignored" half. Found by measurement rather than on the device, so it needed no tablet to confirm.
Cause
strokes.ts sized the pencil with
0.65 + 0.35 * Math.min(1, pr * 2). The* 2is what puts the neutral 0.5 at 1×, which means the clamp bit at exactly neutral — above it, nothing moved. Measured on a straight 24px stroke, as the thickness in pixels:Above 0.5 the pencil was byte-for-byte identical at every pressure. A stylus writes well above 0.5, so the whole range a person actually presses in was flat: indistinguishable from having pressure switched off. The brush, sharing the page, doubles over the same span.
Why the change is safe for existing artwork
Strokes are stored as point lists and re-rendered on every paint, so changing this formula changes drawings that already exist. Dropping the clamp only extends the curve past neutral — the value at and below 0.5 is untouched. Verified by rendering to pixels on both revisions and comparing base64:
A mouse reports no pressure, which reads as the neutral 0.5, so no mouse-drawn stroke moves at all.
The alpha term keeps its clamp
Deliberately, and there is now a comment saying why: the pencil is already fully opaque at neutral, so there is no headroom to press into. Lowering the neutral to make room would re-render every pencil stroke ever drawn, lighter. Above neutral the pencil expresses pressure in its width alone — a real limit, not an oversight, and worth knowing before someone "fixes" it the same way.
Tests
a pencil keeps widening above the neutral pressure— the regression test. Onmain:0.75 is no thicker than neutral: 24 -> 24.a pencil drawn with no pressure is drawn at the neutral weight— pins the invariant that protects existing artwork: the curve must pass through 1× at 0.5, or every pencil stroke re-renders.1282 tests pass;
npm run checkgreen.To try
On the tablet, with 필압 on, draw with the pencil pressing lightly and then hard. The line should visibly thicken now; before, anything past a light press was one fixed width. Existing drawings should look exactly as they did.
The other half of #338 — strokes breaking up — is untouched here and still needs the device.
🤖 Generated with Claude Code