Escher Droste spiral

I wanted to know if an analytic complex-logarithm Droste spiral and a ping-pong mirror tunnel could wrap one live editable HTML card across 10+ octaves of scale, and whether gl.generateMipmap() and anisotropic filtering stay artefact-free on a texElementSubImage2D() texture. Type in the input, switch the card's colour theme, drag the canvas to zoom or twist, and toggle between bilinear, trilinear mipmaps and anisotropic filtering to compare legibility across the inner turns.

DROSTE LIVE 00:00:00 · #00
Type below to update every turn
Theme
2px grid
11 chars · cobalt Mipmap check

Drag canvas to zoom and rotate · tap controls on the outer frame

Mode
Filter
Strands
Starting WebGL 2 Droste stage...
Show the code framed cutout card, complex-log Droste shader, mipmap upload, ping-pong tunnel and hit sync
  1. The framed card with a transparent cutout. Four grid rails carry the live input, theme buttons, ticking clock and 2 px test patterns while #droste-cutout stays empty and lets pointer drags pass through to the canvas.
  2. The conformal Escher Droste fragment shader. Maps screen coordinates through a perspective homography and complex logarithm, wraps each octave to the measured cutout ratio, and passes the analytic Jacobian to textureGrad() so mipmaps and anisotropy stay free of branch-cut seams.
  3. The ping-pong mirror tunnel pass. Composites the live framed card over a shrunk, rotated and colour-shifted copy of the previous framebuffer so every keystroke or button tap echoes down the tunnel.
  4. Uploading with texElementSubImage2D() and building mipmaps. Calls gl.generateMipmap(gl.TEXTURE_2D) right after upload and switches between LINEAR, LINEAR_MIPMAP_LINEAR and EXT_texture_filter_anisotropic.
  5. Keeping the outer frame clickable. Updates canvas.updateElementGeometry() with the outermost card transform and toggles card.dataset.hitTick so Chromium refreshes its hit-test cache.

How it works

M. C. Escher's 1956 lithograph Print Gallery hides a conformal logarithmic spiral inside a rectangular frame, worked out analytically by Hendrik Lenstra and Bart de Smit in 2003. I wanted to test the same mapping on a live HTML form drawn by texElementSubImage2D(), because a Droste spiral packs ten or more octaves of minification into one frame and immediately exposes whether WebGL 2 mipmaps and anisotropic filtering behave on a live DOM texture.

One ElementGL instance from /lib/element-gl.js owns the page's single WebGL 2 context. The source card (#droste-card) is a square 3 by 3 CSS grid whose centre cell (#droste-cutout) has a transparent background and pointer-events: none. Each time the card paints, stage.upload(card) copies its current picture into an RGBA8 texture via gl.texElementSubImage2D(), and when mipmaps are enabled the page calls gl.generateMipmap(gl.TEXTURE_2D) straight afterwards. WebGL 2 permits mipmap chains on non-power-of-two textures, which matters here because a responsive HTML card at device scale 2.625 almost never lands on a power-of-two pixel size.

In Conformal Droste mode, the fragment shader measures the card's actual cutout ratio r1 = cutout.offsetWidth / card.offsetWidth, sets the log-period L = ln(1 / r1), and maps complex coordinates z through w' = (1 + i * strands * L / (2 * pi)) * (ln(z) - offset). Because crossing the atan2 branch cut shifts w' by an exact integer multiple of L and a full 2 * pi turn, wrapping the Chebyshev norm max(|x|, |y|) into [r1, 1] produces no seam. Calling plain texture() across that wrap boundary still spikes hardware screen-space derivatives and leaves a 1 px blurry line, so the shader computes the smooth derivative dFdx(z) and dFdy(z) before the logarithm, multiplies by the analytic complex Jacobian c * zTile / z, and samples with textureGrad(). Tilting the plane in perspective turns the isotropic spiral footprint into an elongated ellipse, which lets you see the difference between LINEAR_MIPMAP_LINEAR and EXT_texture_filter_anisotropic on the 2 px grid and typography.

In Infinite Mirror Tunnel mode, the same stage.gl context drives two small RGBA8 ping-pong framebuffers (capped at 768 px on a side). Pass 1 samples the previous framebuffer shrunk, rotated and subtly hue-shifted, then composites the upright live card over it so the transparent cutout reveals an endless stack of earlier frames. Every keystroke, theme switch or clock tick triggers a short burst of feedback passes so the change ripples down the hall of mirrors before settling to rest.

After layout or view updates, the page calls canvas.updateElementGeometry(card, { canvasTransform }) and increments card.dataset.hitTick so clicks and typing land on the outermost frame. An IntersectionObserver pauses the 1 Hz clock and any auto-zoom loop when the stage leaves the viewport. If WebGL 2 isn't available, a 2D canvas fallback draws concentric nested copies using five-argument drawElementImage(); if HTML-in-canvas isn't enabled or the WebGL context is lost, #droste-card moves out of the canvas so the controls stay usable as plain HTML.

Live checks

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

Findings