Controls that wear with use

Three native controls that keep the marks of being used. Press Save and the paint chips where your finger landed. Press the dark key and it keeps your fingerprint and sits a little lower. Drag the slider and its track wears a dark groove where the thumb has been. The wear is saved in this browser, so it's still there when you come back. Each control is a plain <button> or <input type="range"> drawn by a canvas.

A button whose paint chips

After Aging Button by Florian Kiem.

Pressed 0 times.
Show the code the button, the chips, the holes
  1. The markup. One <button>.
  2. A press. Where it landed and a seed go on a list, and the marks for it are drawn into two plain canvases.
  3. The paint. The button's picture, scuffs on it, holes cut through it, then the metal behind.
  4. The marks. A chip, a scuff and a fingerprint.

A key that sinks and keeps fingerprints

After Realistic Button by Adam Kowalski.

No prints yet.
Show the code the key, the prints, the sinking
  1. The markup. A <button aria-pressed> with a lamp.
  2. A press. A print is stamped where the pointer went down.
  3. The paint. The base, the key drawn lower for every press, and the prints kept on its face.
  4. The marks.

A slider whose track wears a groove

My addition. The same idea on an <input type="range">.

Not moved yet.
Show the code the slider, the groove
  1. The markup.
  2. The count and the paint. Each value the thumb passes is counted, and the counts are drawn as a dark band on the slider's picture.
Show the code saving the wear, the styles, the whole library
  1. Saving. The wear is a list of presses in localStorage, replayed on load.
  2. Styles.
  3. The whole library file.

How it works

Each control has one or two plain canvases its own size that hold its wear. They aren't on the page and they're never read. A press draws a few marks into them, and the visible canvas draws them over the element's picture on every paint.

Chips have to remove paint, and under the paint there has to be metal. That takes three composite modes in one canvas:

  1. drawElementImage() draws the button.
  2. source-atop draws the scuffs, so they stay on the paint.
  3. destination-out draws the chip canvas, which cuts a hole in the button's picture for each chip. The label is cut too.
  4. destination-over draws behind what is left: first a dark, shifted copy of the canvas, which shows as the thickness of the paint at the edge of each hole, then a metal plate.

The button is still a button. Its hit box is its whole box, holes included, and the label a screen reader gets is the element's text, which no chip can remove.

Prints are strokes at low alpha, clipped to the key's face and drawn with source-atop. The key's resting place moves down 0.1 of a pixel for each press, to at most 5, and the base under it stays where it is, so the key gets shorter. The hit box moves with the picture.

The groove counts each value the thumb passes. The slider is dragged natively: the canvas only listens to input.

Saving. A mark is drawn from a seed, so the wear is saved as a short list of presses (where, and the seed) and drawn again on load. I didn't save pixels, which would have meant reading a canvas back.

Live checks

These run on their own canvases in the corner of the window. They don't touch the wear you've made.

Findings