Tilt the phone to light a live card
Three cards made of HTML, drawn through foil, hologram and lenticular shaders. Press "Use the phone's tilt" and tilt the phone: the cards lean and their surfaces change with the angle. Without a sensor, move the pointer or drag a finger across the panel. The buttons on the cards work while they lean. The third card has two faces and shows one or the other by angle.
Canvas Bank
•••• •••• •••• 0042
A. Lovelace
12/29
Admit one
Row 12, seat 4
Grace Hopper
Speaker, hall B
Access code 4821
Lean the other way for the name
The lean follows the pointer. With no input for a moment it moves in a circle.
Show the code tilt → custom properties → shader and hit box
- The markup. Three ordinary blocks.
fxnames the shader. - The page script. One call connects the tilt sensor and the pointer to
--fx-xand--fx-y. The rest handles the button and the badge's faces. - Reading the sensor.
requestPermission()where it exists, thendeviceorientationevents measured from the first angle. - The lean. A perspective matrix from the two numbers. The library uses it for the picture and for hit testing.
- The foil shader.
- The functions the three shaders share.
- Marking the hologram patch.
- The hologram shader.
- Two faces, interleaved in CSS.
- The lenses over them.
- Inside the fx library: the upload and the draw.
How it works
tiltLight()writes the lean to two custom properties on the panel. The fx library passes them to each card's shader asu_xyand to the card'sgeometryfunction, which returns a perspective matrix.- The picture of a card is uploaded once. While the phone tilts only the two numbers change, so the foil and hologram cards cost one draw per frame and no upload.
- The shader can't know which part of a card is the hologram. CSS paints that part magenta, and the shader replaces pixels close to magenta.
- The lenticular card is the exception to "no upload". Its two faces are interleaved by CSS masks whose strip width is computed from
--fx-x, so its picture changes with the lean and is uploaded again. - When the lean crosses zero the page sets
data-faceon the badge, which movespointer-eventsto the face that shows more, and callsnavigator.vibrate(8).
Live checks
Each check builds its own fixture in a corner of the window. The cards above aren't touched.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157 with software rendering and no orientation sensor. The rows above say what your browser does.
- Works: buttons on a leaning card. The perspective matrix goes to
updateElementGeometry(), andelementFromPoint()finds a button at its drawn position at full lean. - Works: a colour as a mask. A magenta block in the DOM is replaced by the shader. The edge of the block is one soft pixel. A card that falls back to plain HTML shows the magenta block.
- Works: lenticular faces in CSS.
mask-imagewith a strip width fromcalc()of a registered property is applied in the picture, and the picture follows the property. - Limit: one input face at a time. Both faces of the badge are in the same place. Which one takes a press is decided by script at the zero crossing, not by what each strip shows.
- Not verified here: everything about the sensor. The test browser has none, so the check above sends a synthetic
deviceorientationevent. Open on the phone: the event rate, the latency, whether Chrome on Android asks for permission, and whethernavigator.vibrate()gives a tick at the flip. The web haptics API isn't in the test browser and isn't used.