Split-flap output element

A departure board made of six <output> elements, drawn by a canvas. The form under the canvas sets their values. When a value changes, the canvas flips each character that differs to its new one, card by card. Type a message, move the delay slider or press Next departure. The Flip menu switches between stepping through the alphabet and turning straight from the old picture to the new one.

Time  Destination  Platform

09:42 EDINBURGH 4 09:55 YORK 11 10:03 MANCHESTER 7 10:10 BRISTOL 2 10:26 PENZANCE 9 MIND THE GAP

 

Show the code output values read on paint, flaps drawn from pieces of elements
  1. The board. Six <output> elements in a drawable section. They belong to the form through the form attribute.
  2. The form, outside the canvas.
  3. The form sets values. Nothing here talks to the canvas.
  4. The styles. Fixed-pitch text, and the drum.
  5. On paint, find what changed. Compare each output's value with the characters the flaps show.
  6. The faces of a flap. A character from the drum, from the live board or from a snapshot of the board.
  7. One flap part way through a flip.
  8. Drawing a piece of an element with the nine-argument drawElementImage().

How it works

Setting output.value changes the element's text, and the browser fires paint on the canvas. The paint handler reads the value of each output and compares it, character by character, with what its flaps show. That comparison is the only link between the form and the board. The canvas code has no input listener and no observer.

Each character has a box, measured with a Range. The canvas draws a card behind every box, then the section itself, so a settled character is the browser's own text and can be selected. A flap in motion is drawn from pieces of elements with the nine-argument form of drawElementImage(), which copies a source rectangle of an element's picture to a destination rectangle.

In the first mode a flap steps through the characters of a drum: a line of text in the same font that holds every character a flap can show. The drum is a second drawable child of the canvas. It's never drawn whole: its characters are drawn one at a time. There's one drum for each style of output, so the yellow row flips in yellow. In the second mode the old face of a flap is a piece of a snapshot taken with captureElementImage() before the change, and the new face is a piece of the live section. That mode needs no drum and works for any character.

Live checks

These run on their own fixtures in the corner of the window, after a tap on the button.

Findings