Origami boarding pass and tear-off stub

I wanted to know if one live HTML boarding pass can fold into concertina panels and rip along a serrated perforation into two separate interactive pieces on a 2D canvas. This builds directly on the sheared-strip folding in /accordion/ and the paper peel in /view-source/, paired with the physical tear-off stub pattern from mobile wallet boarding passes. Edit the passenger name, change the seat, drag the paper body to fold it, or drag the Tear here tab to unzip the stub.

Canvas Air Flight CA 408 Ready
LHR->HND
GateB14 Departs09:40 Date22 NOV
014-8829-408-LHRSEQ 042
Stub CA 408
12A Group 2
PAUL KINLAN
BOARDED

Flat and untorn. Controls use one unclipped five-argument draw per half.

Show the code two drawable halves, 4-panel origami fold, serrated tear, and hit-box restore
  1. The markup. One <canvas content="drawable" layoutsubtree> holding two sibling drawable halves: #pass-main and #pass-stub.
  2. Origami accordion fold. Four hinged panels drawn with nine-argument drawElementImage(), alternating shear, cosine foreshortening, and crease shading.
  3. Serrated tear and fling. Complementary sawtooth clip paths separate the perforation as you drag, then a damped spring flings the detached stub apart.
  4. Restoring hit boxes. After sliced or clipped draws, an empty-clip five-argument draw puts each half's hit region back on its full painted box.
  5. Pointer input. Ignores clicks on form controls so typing and taps keep working, while drags on the handle tear and drags on the paper fold.
  6. Boarding pass layout. Side-by-side on wide screens, stacked with a horizontal perforation below 540 px, plus a CSS barcode.

How it works

I split the boarding pass into two sibling drawable children inside one 2D canvas: #pass-main and #pass-stub. While the pass is flat and untorn, each half takes one unclipped five-argument drawElementImage(el, x, y, w, h) call right beside its neighbour. That keeps every input, select menu, checkbox, and button aligned to its painted pixels.

When you fold the pass, I slice the combined width (or height on a narrow phone screen) into four hinged panels using nine-argument drawElementImage(source, sx, sy, sw, sh, dx, dy, dw, dh), borrowing the alternating shear idea from /accordion/. Cosine foreshortening narrows each panel as the fold angle grows, alternating affine shear builds the mountain and valley ridges, and linear gradients shade the creases.

When you drag the Tear here handle or pull the tear slider, the canvas draws complementary sawtooth clip paths along the perforation seam. Below 75%, the stub pivots away from the remaining uncut hinge like physical ticket paper, inspired by the paper-peel interaction on /view-source/ and wallet pass stubs. Once the rip passes 75%, a damped spring flings #pass-stub clear at a slight angle. At the snap point I take one brief captureElementImage() snapshot of the stub for a faint motion trail and call close() as soon as the spring settles, so zero snapshots stay open at rest.

A nine-argument draw shrinks an element's hit region to that slice. After drawing folded panels or serrated clips, I run an empty-clip five-argument drawElementImage() for each half under its current transform (matching the hit-restore pattern in /lib/text-canvas.js) and toggle a data-hit attribute when motion stops so Chromium clears its hit-test cache. Because #pass-main and #pass-stub are separate drawable children, both halves stay interactive after the tear.

Live checks

These run on isolated fixtures in the corner of the window and leave the boarding pass above untouched. Pixel checks copy each fixture canvas with drawImage() into a plain 2D canvas before calling getImageData().

Findings