Brewster kaleidoscope

I wanted to know if one live interactive HTML card can be reflected across 4-fold, 6-fold, 8-fold, 12-fold and triangular kaleidoscope mirror chambers, and whether Chromium's updateElementGeometry() accepts negative-determinant mirror transforms so buttons, sliders and text inputs keep working in odd-bounce reflections. Type in the input, pick a jewel palette, drag the scale slider or tap "+1 Gem" inside any wedge, and toggle "Show hit-box projection" to watch the hit box flip between cyan (det +1) and magenta (det -1) as you cross each brass mirror seam.

KALEIDOSCOPE 00:00:00
Gems: 00

Hover or tap any wedge to interact ยท drag frame to turn and pan

Chamber
Starting WebGL 2 kaleidoscope stage...
Show the code stained-glass source card, dihedral and p3m1 shader, CPU mirror fold, det -1 hit sync and negative-determinant probe
  1. The live stained-glass source card. One drawable HTML tile holds the text input, four jewel palette buttons, the pattern-scale range slider, the gem counter and the 1 Hz ticking clock.
  2. The dihedral and equilateral-triangle fragment shader. Folds screen coordinates into the fundamental wedge or p3m1 alcove, passes pre-fold derivatives transformed by the reflection matrix to textureGrad() for sharp seams, and adds bevelled brass edges and per-bounce optical glass attenuation.
  3. Exact CPU folding and parity tracking. Runs the same two-mirror dihedral and three-mirror Coxeter reflections on the CPU, tracking reflection parity (det +1 vs det -1) and inverting the exact rigid map into a card-to-canvas DOMMatrix.
  4. Pointer-following updateElementGeometry() with det < 0 fallback. Applies the wedge matrix scaled by geometryUnit() on pointermove and pointerdown, bumps card.dataset.hitTick, and falls back to direct control activation on cold taps or if a browser rejects negative-determinant matrices.
  5. The negative-determinant updateElementGeometry() live check. Places an off-centre button inside a fixture card, applies DOMMatrix().translate(220, 20).scale(-1, 1) scaled by geometryUnit(), and tests both the mirrored and unmirrored coordinates with document.elementsFromPoint().

How it works

David Brewster patented the kaleidoscope in 1817 around two flat mirrors meeting at a submultiple of 180 degrees, and later added a three-mirror triangular chamber whose reflections tile the whole plane. I built this experiment to see what happens when the object cell at the end of a Brewster tube is a live interactive HTML card uploaded with texElementSubImage2D(), and in particular whether Chromium's hit-tester accepts a mirror-reflected DOMMatrix whose determinant is negative.

One ElementGL instance from /lib/element-gl.js owns the page's single WebGL 2 context. Each time the card paints, stage.upload(card) copies its current picture into an RGBA8 texture via gl.texElementSubImage2D() and calls gl.generateMipmap(gl.TEXTURE_2D) so narrow 12-fold wedges and zoomed-out triangle tiles stay sharp. In the four dihedral chambers (D4, D6, D8 and D12), the fragment shader turns the polar angle modulo pi / n into a wedge index k; even wedges rotate directly into the fundamental wedge (det = +1) while odd wedges reflect across the mirror bisector (det = -1). In the triangular wallpaper chamber (p3m1), the shader reflects any point outside the three mirror walls of the central equilateral triangle across the most-violated wall until it lands inside the alcove; because the equilateral triangle is a Coxeter alcove, each reflection drops the exact reflection depth by one and counts optical bounces directly.

Sampling a folded coordinate directly with texture() spikes hardware derivatives across every mirror line and leaves a 1 px soft seam. Instead, the shader computes dFdx(u) and dFdy(u) on the smooth unfolded chamber plane, rotates and reflects those derivative vectors by the same orthogonal matrix Q that folded the point, and samples with textureGrad(). Each bounce multiplies the RGB output by a slight green-warm optical glass factor, and the Euclidean distance to the nearest mirror wall drives a thin bevelled brass seam.

On pointermove and pointerdown in capture phase, the CPU runs the exact same fold for the pointer's canvas coordinates, tracks total parity (det +1 for even bounces, det -1 for odd mirror bounces), and builds the rigid Euclidean affine DOMMatrix mapping card CSS pixels onto that specific wedge or triangle. It scales that matrix by geometryUnit() from /lib/surface.js, calls canvas.updateElementGeometry(card, { canvasTransform }), and increments card.dataset.hitTick to clear Chromium's hit-test cache. Because every reflection is an exact isometry inside a wedge, the reprojected quad matches the drawn wedge pixel for pixel; turning on "Show hit-box projection" draws the active quad in cyan for direct wedges (det +1) and magenta for reflected wedges (det -1), with a top-left bracket so you can see the handedness flip across every seam. If you tap cold on a touchscreen without hovering first, or if a browser ignores negative-determinant transforms in updateElementGeometry(), the capture handler falls back to activating the button, focusing the input or updating the range slider from the folded local coordinate, and reports whether the last tap landed natively or via fallback.

An IntersectionObserver pauses the 1 Hz clock and any barrel-turn animation when the stage scrolls off screen. If WebGL 2 isn't available, a 2D canvas fallback clips and reflects the wedges with five-argument drawElementImage(); if HTML-in-canvas isn't enabled or the WebGL context is lost, #kaleido-card moves out of the canvas and stays usable as plain HTML.

Live checks

These checks wait for a tap so the page opens with one GPU context. Each check builds its own small fixture on the test stage and retires its canvas when finished.

Findings