A counter that turns
Craft 05 · Motion, web
Drums, not digits.
A count-up built the way a real counter is: one drum per place. Play with it.
0
Where it came from
Fefys celebrates with numbers, and in November I went through three versions of its count-up in forty minutes. The app shipped the third, built on a library, which was the right call for an app with a deadline. The one I kept thinking about was the second: an odometer I wrote myself, with a wheel for every digit and a carry that worked like a real one. It had faults I didn't have time for then. This is that idea, finished.
Drums, not digits
A real counter doesn't slide digits in and out. Each place is a drum, a short cylinder with 0 to 9 printed around it, and you see the face that's turned towards you through a window. So that's what this draws. Every frame, each of the ten digits on a drum is rotated to its place on the cylinder, 36 degrees apart, around an axis set back behind the window, so the digit facing you is drawn at its true size and the others shrink as they curve away. A digit fades with the square of how directly it faces you, so the ones curving away darken the way printed numbers do on a real drum, and the window's top and bottom edges fade into shadow.
digits.current[place]?.forEach((span, digit) => {
const delta = ((digit - position + 15) % 10) - 5;
const angle = delta * STEP;
const facing = Math.cos((angle * Math.PI) / 180);
span.style.opacity =
Math.abs(angle) >= 90 ? "0" : String(0.12 + 0.88 * facing ** 2);
span.style.transform = `translateZ(${-radius}px) rotateX(${-angle}deg) translateZ(${radius}px)`;
});The carry
The carry is the function from Fefys, unchanged. A drum above the units only turns during the last tenth of the drum below it, the way a real odometer's tens wheel waits for the units to come round. Go from 1,299 to 1,300 and the tens and hundreds drums sit still until the units pass 9, then all three roll over together.
export function wheelPosition(shown: number, place: number) {
const unit = 10 ** place;
if (place === 0) return shown % 10;
const base = Math.floor(shown / unit) % 10;
const lower = shown % unit;
const carry = Math.max(0, lower - (unit - 1));
return base + carry;
}Speed you can see
Each drum gets its own blur, vertical only, sized by how fast that drum is turning right now. A big jump smears the units into a streak while the thousands barely move; a +1 stays sharp. How long a move takes grows with the size of the change rather than in proportion to it, so one step is quick and a jump of sixty thousand takes its time without dragging, and every move eases out to rest with no overshoot.
let moved = Math.abs(position - last[place]);
if (moved > 5) moved = 10 - moved;
const speed = (moved / dt) * 1000;
blurs.current[place]?.setAttribute(
"stdDeviation",
`0 ${still ? 0 : Math.min(7, speed * 0.05).toFixed(2)}`,
);
const durationFor = (distance: number) =>
Math.min(2600, 420 + 520 * Math.log10(distance + 1));In your hand
Drag it and the units drum follows your finger, one drum height per number, with the carries rippling up as you go. Let go and it keeps a third of a second of your speed, coasts and settles on a whole number, never between two. The drums never change size and the leading zeros stay, just dimmed, so the number never shifts while it counts. For anyone who prefers reduced motion, it goes straight to the number.
const onPointerUp = () => {
if (!drag.current) return;
const { speed } = drag.current;
drag.current = null;
const coast = speed * FLICK_PROJECTION;
goTo(shown.current + coast, 380 + Math.min(1600, Math.abs(coast) * 60));
};