The showcase prompt, round 3, Opus 5.5

agent
Claude Code 2.1.322
model
claude-opus-5-5
harness
Claude Code
started
2026-11-11 08:04 UTC
took
20 min · 58 turns

user

+0:00

I need you to create the most impressive thing you can make: the thing that shows what you do best. People ask me which models I use, and I want to answer by showing them this. It needs to be embeddable in a post, and I'll write the preface. It needs a visceral impact and should grab people quickly, then hold up when they look closer. It doesn't have to be about you or about me. Pick what you're best at and let the work be the proof. Be amazingly clever about this.

agent

+3:17
  • Bashls -la; which node chromium chromium-browser google-chrome firefox python3 npx; node --version; ls ~/.cache/ms-playwright 2>/dev/null; pip list 2>/dev/null | grep -i -E "playwright|selenium|pyppeteer"; nvidia-smi 2>&1 | head -5

    command

    ls -la; which node chromium chromium-browser google-chrome firefox python3 npx; node --version; ls ~/.cache/ms-playwright 2>/dev/null; pip list 2>/dev/null | grep -i -E "playwright|selenium|pyppeteer"; nvidia-smi 2>&1 | head -5

    result, 9 lines

    total 8
    drwx------ 2 runner runner 4096 Nov 11 08:04 .
    drwx------ 3 runner runner 4096 Nov 11 08:04 ..
    /opt/node/bin/node
    /usr/bin/chromium-browser
    /usr/bin/python3
    /opt/node/bin/npx
    v22.21.1
    /bin/bash: line 1: nvidia-smi: command not found
  • Bashchromium-browser --version 2>&1; ls /opt/node/lib/node_modules; npm ls -g 2>/dev/null | head

    command

    chromium-browser --version 2>&1; ls /opt/node/lib/node_modules; npm ls -g 2>/dev/null | head

    result, 10 lines

    Command '/usr/bin/chromium-browser' requires the chromium snap to be installed.
    Please install it with:
    
    snap install chromium
    
    corepack
    npm
    /opt/node/lib
    ├── corepack@0.34.0
    └── npm@10.9.4
  • Bashcd /tmp && mkdir -p pw && cd pw && npm init -y >/dev/null && timeout 300 npm i puppeteer 2>&1 | tail -3; ls ~/.cache/puppeteer 2>/dev/null

    command

    cd /tmp && mkdir -p pw && cd pw && npm init -y >/dev/null && timeout 300 npm i puppeteer 2>&1 | tail -3; ls ~/.cache/puppeteer 2>/dev/null

    result, 6 lines

      run `npm fund` for details
    
    found 0 vulnerabilities
    chrome
    chrome-headless-shell
    Shell cwd was reset to ~/run
  • Bashcd /tmp/pw && cat > gltest.mjs <<'EOF'

    command

    cd /tmp/pw && cat > gltest.mjs <<'EOF'
    import puppeteer from 'puppeteer';
    const b = await puppeteer.launch({headless:'new', args:['--use-angle=swiftshader','--enable-unsafe-swiftshader','--ignore-gpu-blocklist']});
    const p = await b.newPage();
    await p.setContent('<canvas id=c></canvas>');
    const r = await p.evaluate(()=>{const gl=document.getElementById('c').getContext('webgl2'); if(!gl) return 'no webgl2'; return [gl.getParameter(gl.VERSION), gl.getParameter(gl.MAX_TEXTURE_SIZE), !!gl.getExtension('EXT_color_buffer_float')];});
    console.log(r); await b.close();
    EOF
    node gltest.mjs

    result, 2 lines

    [ 'WebGL 2.0 (OpenGL ES 3.0 Chromium)', 8192, true ]
    Shell cwd was reset to ~/run

agent

+9:35
reasoning

I'm building a self-contained HTML file that ray-traces a black hole, with the accretion disk written into the file's own source, so hovering over any light point traces back to the line that drew it.

  • Write~/run/accretion.html

    input

    ~/run/accretion.html
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <!--
      ACCRETION
    
      You are reading the outer edge of an accretion disk. Every glyph in it,
      these included, is one character of the file that draws it: the HTML, the
      CSS, the JavaScript, and the shader that bends the light. The file is laid
      down in reading order, ring by ring, from the outside in, and it ends at the
      innermost stable circular orbit, three Schwarzschild radii out, where the
      last line is still circling.
    
      Nothing here is a texture, a model or a video. Each pixel is a photon traced
      backwards from your eye through curved spacetime until it strikes the disk,
      falls through the horizon, or escapes to the stars. Hover over any light and
      the page will follow that photon home and tell you which line it came from.
    -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <title>Accretion</title>
    <style>
      :root { --ink: #f1e4d2; --dim: #8a8075; --hot: #ffb466; --ice: #8fd6ff; }
      [hidden] { display: none !important; }
      html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--ink);
        font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace;
        -webkit-font-smoothing: antialiased; }
      canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
      #gl { cursor: crosshair; touch-action: none; }
      #gl.drag { cursor: grabbing; }
      #ink { pointer-events: none; }
      header, footer { position: absolute; left: 20px; pointer-events: none; transition: opacity 1.2s; }
      header { top: 18px; right: 120px; }
      header h1 { margin: 0; font-size: 13px; font-weight: 500; letter-spacing: .55em; }
      header p { margin: 6px 0 0; max-width: 31em; color: var(--dim); }
      footer { bottom: 16px; right: 20px; color: var(--dim); }
      kbd { font: inherit; color: var(--ink); border: 1px solid #ffffff2a; border-radius: 3px; padding: 0 4px; }
      .quiet header, .quiet footer, .quiet #open { opacity: 0; }
      #probe { position: absolute; max-width: min(460px, 86vw); padding: 10px 12px 11px; pointer-events: none;
        background: #050403d0; border: 1px solid #ffffff1c; border-radius: 6px;
        -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); box-shadow: 0 8px 40px #000a; }
      #probe .k { color: var(--dim); letter-spacing: .12em; font-size: 10.5px; text-transform: uppercase; }
      #probe .k b { color: var(--ice); font-weight: 500; }
      #probe .ln { margin: 6px 0 7px; white-space: pre; overflow: hidden; color: #d9cbb8; }
      #probe .ln i { font-style: normal; color: #000; background: var(--ice); border-radius: 2px; }
      #probe .ph { color: var(--hot); }
      #probe .note { margin-top: 5px; color: #b9ad9f; white-space: normal; }
      button { font: inherit; color: var(--ink); background: #0008; border: 1px solid #ffffff26; border-radius: 4px;
        padding: 4px 10px; cursor: pointer; }
      button:hover { border-color: #ffffff60; }
      #open { position: absolute; top: 16px; right: 16px; transition: opacity 1.2s; }
      #src { position: absolute; top: 0; right: 0; bottom: 0; width: min(600px, 100vw); display: flex; flex-direction: column;
        background: #050403e6; border-left: 1px solid #ffffff1a; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
      #src .bar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid #ffffff14; color: var(--dim); }
      #src .bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
      #code { flex: 1; margin: 0; padding: 12px 14px 40vh; border: 0; outline: 0; resize: none; background: transparent;
        color: #e2d5c3; font: 11.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; tab-size: 2; }
      #code::selection { background: #8fd6ff55; }
      @media (max-width: 560px) { header p { display: none; } footer { font-size: 11px; } }
    </style>
    </head>
    <body>
    <canvas id="gl"></canvas>
    <canvas id="ink"></canvas>
    <header>
      <h1>ACCRETION</h1>
      <p>A black hole whose disk is written in its own source code. Every point of light is one character of this page, bent by the gravity it describes.</p>
    </header>
    <div id="probe" hidden></div>
    <footer id="hint">hover any light to trace it to its line of code · drag to orbit · scroll to fall in · <kbd>space</kbd> stops time · <kbd>s</kbd> source</footer>
    <button id="open">{ } source</button>
    <aside id="src" hidden>
      <div class="bar"><span>edit me. your words go into orbit.</span><button id="reset">reset</button><button id="close">close</button></div>
      <textarea id="code" spellcheck="false" autocomplete="off" autocapitalize="off"></textarea>
    </aside>
    <script>
    (function () {
    'use strict';
    
    // ─── Units ──────────────────────────────────────────────────────────────────
    // Lengths are measured in Schwarzschild radii: r_s = 2GM/c² = 1, so the event
    // horizon is the unit sphere and the mass is M = 1/2. Light speed is 1.
    //
    //   r = 1     event horizon. Nothing inside it gets out.
    //   r = 1.5   photon sphere. Light can orbit here, unstably, forever.
    //   r = 2.6   apparent radius of the shadow, (3√3/2) r_s. Any ray aimed
    //             closer to the hole than this is captured.
    //   r = 3     innermost stable circular orbit (ISCO). The disk ends here.
    
    const TAU = Math.PI * 2;
    const R_IN = 3.0;          // ISCO: the inner edge of the disk
    const R_TEXT = 14.0;       // the text occupies R_IN..R_TEXT
    const R_GAS = 18.5;        // beyond the text, only warm gas fading out
    const SPIN = 2.4;          // simulated time per wall-clock second
    const MAX_STEPS = 420;     // integration steps per photon
    const SHADOW = 1.5 * Math.sqrt(3);
    
    const clamp = (x, a, b) => Math.min(b, Math.max(a, x));
    
    function boot() {
      // ─── The text ─────────────────────────────────────────────────────────────
      // The page reads itself. This happens before the script touches the DOM, so
      // what goes into the disk is the document exactly as it arrived.
      const SOURCE = '<!DOCTYPE html>\n' + document.documentElement.outerHTML;
    
      const $ = (id) => document.getElementById(id);
      const canvas = $('gl'), ink = $('ink'), pen = ink.getContext('2d');
      const probeEl = $('probe'), srcEl = $('src'), codeEl = $('code'), hintEl = $('hint');
      const embedded = window.self !== window.top;
      const touchy = matchMedia('(pointer: coarse)').matches;
      if (/quiet/.test(location.hash)) document.body.classList.add('quiet');
    
      const gl = canvas.getContext('webgl2', {
        antialias: false, alpha: false, depth: false, stencil: false, powerPreference: 'high-performance'
      });
      if (!gl) {
        document.querySelector('header p').textContent =
          'This page needs WebGL2 to bend light, and this browser does not offer it.';
        return;
      }
      // Half-float render targets let the disk be brighter than "white", so bloom
      // and tone mapping behave like a camera rather than a clipped screen.
      const HDR = !!gl.getExtension('EXT_color_buffer_float');
      const STORE = HDR ? 1 : 0.25;
    
      // ─── Shaders ──────────────────────────────────────────────────────────────
      const VERT = `#version 300 es
    out vec2 vUv;
    void main() {
      // One triangle that covers the screen; no vertex buffers needed.
      vec2 p = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2);
      vUv = p;
      gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
    }`;
    
      // The heart of it. Runs once per pixel, every frame.
      const SCENE = `#version 300 es
    precision highp float;
    precision highp int;
    in vec2 vUv;
    out vec4 outColor;
    
    uniform vec2  uRes;
    uniform vec3  uCam;
    uniform mat3  uBasis;     // camera right, up, forward
    uniform float uTan;       // tan(vertical fov / 2)
    uniform float uTime;      // disk time
    uniform float uRingH;     // radial height of one ring of text
    uniform float uCols;      // glyph atlas columns
    uniform vec2  uCell;      // one atlas cell, in texture coordinates
    uniform float uCellPx;    // one atlas cell height, in texels
    uniform float uStore;     // 1 for float targets, 1/4 for 8-bit fallback
    uniform ivec2 uHi;        // character range to light up (the probed line)
    uniform sampler2D uAtlas, uChars, uRings;
    
    const float TAU = 6.28318530718;
    const float R_IN = ${R_IN.toFixed(3)}, R_TEXT = ${R_TEXT.toFixed(3)}, R_GAS = ${R_GAS.toFixed(3)};
    
    float hash13(vec3 p) {
      p = fract(p * 0.1031);
      p += dot(p, p.zyx + 31.32);
      return fract((p.x + p.y) * p.z);
    }
    vec3 hash33(vec3 p) {
      p = fract(p * vec3(0.1031, 0.1030, 0.0973));
      p += dot(p, p.yxz + 33.33);
      return fract((p.xxy + p.yxx) * p.zyx);
    }
    float noise(vec3 p) {
      vec3 i = floor(p), f = fract(p);
      f = f * f * (3.0 - 2.0 * f);
      return mix(mix(mix(hash13(i), hash13(i + vec3(1,0,0)), f.x),
                     mix(hash13(i + vec3(0,1,0)), hash13(i + vec3(1,1,0)), f.x), f.y),
                 mix(mix(hash13(i + vec3(0,0,1)), hash13(i + vec3(1,0,1)), f.x),
                     mix(hash13(i + vec3(0,1,1)), hash13(i + vec3(1,1,1)), f.x), f.y), f.z);
    }
    
    // Colour of a black body at temperature t (kelvin). Krystek's fit to the
    // Planckian locus in CIE 1960 UCS, converted to linear sRGB at unit luminance.
    vec3 blackbody(float t) {
      t = clamp(t, 1000.0, 15000.0);
      float u = (0.860117757 + 1.54118254e-4 * t + 1.28641212e-7 * t * t)
              / (1.0 + 8.42420235e-4 * t + 7.08145163e-7 * t * t);
      float v = (0.317398726 + 4.22806245e-5 * t + 4.20481691e-8 * t * t)
              / (1.0 - 2.89741816e-5 * t + 1.61456053e-7 * t * t);
      float x = 3.0 * u / (2.0 * u - 8.0 * v + 4.0);
      float y = 2.0 * v / (2.0 * u - 8.0 * v + 4.0);
      vec3 XYZ = vec3(x / y, 1.0, (1.0 - x - y) / y);
      vec3 rgb = mat3(3.2404542, -0.9692660, 0.0556434,
                     -1.5371385,  1.8760108, -0.2040259,
                     -0.4985314,  0.0415560,  1.0572252) * XYZ;
      return max(rgb, 0.0);
    }
    
    // Distant stars: one candidate star per cell of a 3D grid, at three scales,
    // looked up by the direction a photon finally escapes in. Because that
    // direction has been bent, the sky near the shadow is a warped mirror.
    vec3 sky(vec3 d) {
      float pix = 2.0 * uTan / uRes.y;
      vec3 c = vec3(0.0);
      for (int l = 0; l < 3; l++) {
        float sc = 45.0 * pow(2.3, float(l));
        vec3 id = floor(d * sc);
        vec3 h = hash33(id + float(l) * 71.0);
        vec3 s = normalize(id + 0.5 + (h - 0.5) * 0.8);
        float dist = length(d - s) / max(pix, 1e-4);
        float lum = pow(h.x, 22.0) * 3.0 / (1.0 + float(l));
        c += lum * exp(-dist * dist * 1.4) * mix(vec3(1.0, 0.72, 0.5), vec3(0.65, 0.8, 1.0), h.z);
      }
      vec3 n = normalize(vec3(0.25, 0.92, -0.3));
      float band = exp(-pow(dot(d, n) / 0.22, 2.0));
      c += band * noise(d * 5.0) * noise(d * 13.0) * vec3(0.05, 0.035, 0.05);
      return c;
    }
    
    // What the disk looks like where a photon crosses it at p, travelling along
    // dir, with a footprint of 'foot' world units (used to choose a mip level).
    vec4 disk(vec3 p, vec3 dir, float foot) {
      float r = length(p.xz);
      float phi = atan(p.z, p.x);
    
      // Gas moves on circular orbits. Measured by an observer hovering in place,
      // its speed is beta = sqrt(M / (r - 2M)): exactly c/2 at the ISCO.
      float beta = sqrt(0.5 / (r - 1.0));
      float gamma = inversesqrt(1.0 - beta * beta);
      vec3 vel = vec3(-sin(phi), 0.0, cos(phi));
      // The photon travels toward us, opposite to the ray we traced. The shift
      // g = nu_seen / nu_emitted combines Doppler and gravitational redshift.
      float g = sqrt(1.0 - 1.0 / r) / (gamma * (1.0 - beta * dot(vel, -dir)));
    
      // Temperature falls outward; we see it multiplied by g. The approaching
      // side is bluer and brighter, the receding side redder and dimmer.
      float T = 8200.0 * pow(r / R_IN, -0.6) * g;
      float I = pow(r / R_IN, -1.45) * pow(g, 3.0);
    
      float cov = 0.0, kind = 0.0, hi = 0.0, ang = phi, rf = 0.0;
      if (r < R_TEXT) {
        // Which ring, which character, and where inside the character?
        rf = (r - R_IN) / uRingH;
        vec4 ring = texelFetch(uRings, ivec2(int(rf), 0), 0); // start, count, omega
        ang = phi - ring.z * uTime;          // rotate with this ring's orbit
        float s = -ang / TAU * ring.y;       // characters run clockwise
        s -= ring.y * floor(s / ring.y);
        float j = floor(s);
        int idx = int(ring.x) + int(j);
        vec4 cd = texelFetch(uChars, ivec2(idx & 1023, idx >> 10), 0);
        float glyph = floor(cd.r * 255.0 + 0.5);
        kind = cd.g;
        vec2 cell = vec2(mod(glyph, uCols), floor(glyph / uCols));
        vec2 uv = (cell + vec2(s - j, fract(rf))) * uCell;
        float lod = log2(max(foot / uRingH * uCellPx, 1e-3));
        cov = textureLod(uAtlas, uv, lod).r;
        hi = (idx >= uHi.x && idx < uHi.y) ? 1.0 : 0.0;
      } else {
        ang = phi - sqrt(0.5 / (r * r * r)) * uTime;
      }
    
      // Gas between the letters: streaks in the co-rotating frame.
      vec2 q = r * vec2(cos(ang), sin(ang));
      float gas = 0.05 + 0.11 * noise(vec3(q * 1.7, r * 3.0)) * noise(vec3(q * 0.4, r * 9.0) + 7.0);
    
      float fade = smoothstep(R_IN, R_IN + 0.03, r) * (1.0 - smoothstep(R_TEXT + 0.5, R_GAS, r));
      float text = cov * (kind > 0.5 ? 0.78 : 1.0);
      vec3 col = blackbody(T) * I * (gas + 1.3 * text);
      col = mix(col, vec3(0.45, 0.85, 1.4) * (0.35 + 2.6 * cov) * max(I, 0.35), hi);
      float alpha = clamp((0.42 + 0.55 * cov) * fade, 0.0, 1.0);
      return vec4(col * fade, alpha);
    }
    
    void main() {
      vec2 ndc = vUv * 2.0 - 1.0;
      vec3 v = normalize(uBasis * vec3(ndc.x * uTan * uRes.x / uRes.y, ndc.y * uTan, 1.0));
      vec3 x = uCam;
    
      // Light in Schwarzschild spacetime obeys u'' + u = (3/2) u² with u = 1/r.
      // A particle in flat space feeling a = -(3/2) h² x / |x|^5, where
      // h = |x × v| is its (conserved) angular momentum, traces exactly the same
      // path. So we integrate that, and every curve below is a true geodesic.
      vec3 hv = cross(x, v);
      float h2 = dot(hv, hv);
    
      vec3 col = vec3(0.0);
      float trans = 1.0, travelled = 0.0;
      float pix = 2.0 * uTan / uRes.y;
      float far = max(length(uCam), R_GAS) + 1.0;
      bool escaped = false;
    
      for (int i = 0; i < ${MAX_STEPS}; i++) {
        float r = length(x);
        float dt = clamp(0.05 * r, 0.012, 4.0) / length(v);   // finer near the hole
        vec3 a = -1.5 * h2 * x / (r * r * r * r * r);
        vec3 xn = x + v * dt + 0.5 * a * dt * dt;               // velocity Verlet
        float rn = length(xn);
        vec3 vn = v + 0.5 * (a - 1.5 * h2 * xn / (rn * rn * rn * rn * rn)) * dt;
        float seg = length(xn - x);
    
        if (x.y * xn.y < 0.0) {                                 // crossed the disk plane
          float f = x.y / (x.y - xn.y);
          vec3 p = mix(x, xn, f);
          float rp = length(p.xz);
          if (rp > R_IN && rp < R_GAS) {
            vec3 d = normalize(mix(v, vn, f));
            float foot = (travelled + seg * f) * pix / sqrt(max(abs(d.y), 0.03));
            vec4 e = disk(p, d, foot);
            col += trans * e.rgb;                               // emission, front to back
            trans *= 1.0 - e.a;
            if (trans < 0.01) break;
          }
        }
        travelled += seg;
        x = xn; v = vn;
        if (rn < 1.0) break;                                    // through the horizon
        if (rn > far && dot(x, v) > 0.0) { escaped = true; break; }
      }
      if (escaped) col += trans * sky(normalize(v));
      outColor = vec4(col * uStore, 1.0);
    }`;
    
      // Bloom: a dual-filter blur pyramid, so bright text glows like it would
      // through a real lens.
      const DOWN = `#version 300 es
    precision highp float;
    in vec2 vUv; out vec4 o;
    uniform sampler2D uTex; uniform vec2 uTexel;
    void main() {
      vec2 h = uTexel;
      o = (texture(uTex, vUv) * 4.0 + texture(uTex, vUv - h) + texture(uTex, vUv + h)
         + texture(uTex, vUv + vec2(h.x, -h.y)) + texture(uTex, vUv - vec2(h.x, -h.y))) / 8.0;
    }`;
    
      const UP = `#version 300 es
    precision highp float;
    in vec2 vUv; out vec4 o;
    uniform sampler2D uTex; uniform vec2 uTexel;
    void main() {
      vec2 h = uTexel;
      o = (texture(uTex, vUv + vec2(-2.0 * h.x, 0.0)) + texture(uTex, vUv + vec2(2.0 * h.x, 0.0))
         + texture(uTex, vUv + vec2(0.0, -2.0 * h.y)) + texture(uTex, vUv + vec2(0.0, 2.0 * h.y))
         + 2.0 * (texture(uTex, vUv + h) + texture(uTex, vUv - h)
                + texture(uTex, vUv + vec2(h.x, -h.y)) + texture(uTex, vUv - vec2(h.x, -h.y)))) / 12.0;
    }`;
    
      const FINAL = `#version 300 es
    precision highp float;
    in vec2 vUv; out vec4 o;
    uniform sampler2D uScene, uBloom;
    uniform float uInv, uBloomK, uSeed;
    vec3 aces(vec3 x) { return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0); }
    void main() {
      vec3 c = texture(uScene, vUv).rgb * uInv;
      vec3 b = texture(uBloom, vUv).rgb * uInv;
      c = aces((c + b * uBloomK) * 1.15);
      vec2 q = vUv - 0.5;
      c *= 1.0 - dot(q, q) * 0.7;
      c = pow(c, vec3(1.0 / 2.2));
      float n = fract(sin(dot(gl_FragCoord.xy + uSeed, vec2(12.9898, 78.233))) * 43758.5453);
      o = vec4(c + (n - 0.5) / 160.0, 1.0);
    }`;
    
      function program(fs) {
        const p = gl.createProgram();
        for (const [type, src] of [[gl.VERTEX_SHADER, VERT], [gl.FRAGMENT_SHADER, fs]]) {
          const s = gl.createShader(type);
          gl.shaderSource(s, src);
          gl.compileShader(s);
          if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s));
          gl.attachShader(p, s);
        }
        gl.linkProgram(p);
        if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p));
        const u = {};
        for (let i = gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i--;) {
          const name = gl.getActiveUniform(p, i).name;
          u[name] = gl.getUniformLocation(p, name);
        }
        return { p, u };
      }
      const scene = program(SCENE), down = program(DOWN), up = program(UP), final = program(FINAL);
      gl.bindVertexArray(gl.createVertexArray());
    
      function texture(filter, wrap) {
        const t = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, t);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter === gl.NEAREST ? gl.NEAREST : gl.LINEAR);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap);
        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap);
        return t;
      }
      function target(w, h) {
        const tex = texture(gl.LINEAR, gl.CLAMP_TO_EDGE);
        gl.texImage2D(gl.TEXTURE_2D, 0, HDR ? gl.RGBA16F : gl.RGBA8, w, h, 0, gl.RGBA,
          HDR ? gl.HALF_FLOAT : gl.UNSIGNED_BYTE, null);
        const fb = gl.createFramebuffer();
        gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
        return { tex, fb, w, h };
      }
    
      // ─── Laying the file into the disk ────────────────────────────────────────
      // Comments are prose and glow a little softer than code. The scanner checks
      // characters one at a time so that it never trips over its own source.
      const SL = '/', ST = '*', HTML_OPEN = '<' + '!--', HTML_CLOSE = '--' + '>';
      function commentMask(text) {
        const mask = new Uint8Array(text.length);
        const upto = (i, s) => { const e = text.indexOf(s, i); return e < 0 ? text.length : e + s.length; };
        for (let i = 0; i < text.length;) {
          const c = text[i], d = text[i + 1];
          let end = i;
          if (c === '<' && text.startsWith(HTML_OPEN, i)) end = upto(i + 4, HTML_CLOSE);
          else if (c === SL && d === ST) end = upto(i + 2, ST + SL);
          else if (c === SL && d === SL) end = upto(i + 2, '\n') - 1;
          if (end > i) { mask.fill(1, i, end); i = end; } else i++;
        }
        return mask;
      }
    
      // Which language is spoken at a given offset? GLSL lives inside JavaScript
      // template strings, which live inside a script tag, which lives in HTML.
      function languages(text) {
        const spans = (open, close) => {
          const out = [];
          for (let i = text.indexOf(open); i >= 0; i = text.indexOf(open, i + 1)) {
            const e = text.indexOf(close, i + open.length);
            out.push([i, e < 0 ? text.length : e]);
            if (e < 0) break;
          }
          return out;
        };
        const table = [
          ['GLSL', spans('\x60#version', '\x60')],
          ['JavaScript', spans('<scr' + 'ipt>', '</scr' + 'ipt>')],
          ['CSS', spans('<style>', '</style>')]
        ];
        return (off) => {
          for (const [name, list] of table) for (const [a, b] of list) if (off > a && off < b) return name;
          return 'HTML';
        };
      }
    
      // Concentric rings, read from the outside in. Each ring holds as many
      // characters as fit around its circumference, so a character has the same
      // width everywhere. Each ring is rigid and turns at its own Keplerian rate,
      // Ω = sqrt(M / r³), which in Schwarzschild coordinates happens to be exact.
      const CELL_W = 40, CELL_H = 64, COLS = 16;
      let L = null;
      function layout(text) {
        const mask = commentMask(text);
        const chars = [], where = [], kinds = [];
        let gap = false;
        for (let i = 0; i < text.length; i++) {
          const c = text[i];
          if (c === ' ' || c === '\n' || c === '\t' || c === '\r') { gap = chars.length > 0; continue; }
          if (gap) { chars.push(' '); where.push(i - 1); kinds.push(mask[i - 1]); gap = false; }
          chars.push(c); where.push(i); kinds.push(mask[i]);
        }
        if (!chars.length) { chars.push(' '); where.push(0); kinds.push(0); }
        const n = chars.length, span = R_TEXT - R_IN;
    
        const capacity = (R, cw) => {
          let c = 0;
          for (let k = 0; k < R; k++) c += Math.floor(TAU * (R_IN + (k + 0.5) * span / R) / cw);
          return c;
        };
        let R = 6;
        while (capacity(R, 0.6 * span / R) < n) R++;
        let lo = 0.6 * span / R, hi = 2 * lo;
        for (let i = 0; i < 40; i++) { const m = (lo + hi) / 2; if (capacity(R, m) >= n) lo = m; else hi = m; }
    
        const rings = new Float32Array(R * 4);
        let start = 0;
        for (let k = R - 1; k >= 0; k--) {
          const rc = R_IN + (k + 0.5) * span / R;
          const count = Math.floor(TAU * rc / lo);
          rings.set([start, count, Math.sqrt(0.5 / (rc * rc * rc)), rc], k * 4);
          start += count;
        }
    
        // Every distinct character gets a cell in the glyph atlas.
        const glyphs = [' '], index = new Map([[' ', 0]]);
        for (const c of chars) if (!index.has(c) && glyphs.length < 256) { index.set(c, glyphs.length); glyphs.push(c); }
        const rows = Math.ceil(start / 1024);
        const data = new Uint8Array(rows * 1024 * 4);
        for (let i = 0; i < n; i++) {
          data[i * 4] = index.has(chars[i]) ? index.get(chars[i]) : index.get('?') || 0;
          data[i * 4 + 1] = kinds[i] * 255;
        }
    
        const lineStarts = [0];
        for (let i = 0; i < text.length; i++) if (text[i] === '\n') lineStarts.push(i + 1);
        return { text, where, n, R, ringH: span / R, rings, glyphs, data, rows, lineStarts, lang: languages(text) };
      }
    
      const atlasTex = texture(gl.LINEAR_MIPMAP_LINEAR, gl.CLAMP_TO_EDGE);
      const charTex = texture(gl.NEAREST, gl.CLAMP_TO_EDGE);
      const ringTex = texture(gl.NEAREST, gl.CLAMP_TO_EDGE);
      let atlasKey = '', atlasRows = 1;
    
      function upload(text) {
        L = layout(text);
        const key = L.glyphs.join('');
        if (key !== atlasKey) {
          atlasKey = key;
          atlasRows = Math.ceil(L.glyphs.length / COLS);
          const c = document.createElement('canvas');
          c.width = COLS * CELL_W; c.height = atlasRows * CELL_H;
          const g = c.getContext('2d');
          g.fillStyle = '#000'; g.fillRect(0, 0, c.width, c.height);
          g.fillStyle = '#fff'; g.textAlign = 'center'; g.textBaseline = 'middle';
          g.font = '600 46px ui-monospace, SFMono-Regular, Menlo, Consolas, "DejaVu Sans Mono", monospace';
          L.glyphs.forEach((ch, i) =>
            g.fillText(ch, (i % COLS + 0.5) * CELL_W, (Math.floor(i / COLS) + 0.5) * CELL_H + 2));
          gl.bindTexture(gl.TEXTURE_2D, atlasTex);
          gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
          gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, c);
          gl.generateMipmap(gl.TEXTURE_2D);
        }
        gl.bindTexture(gl.TEXTURE_2D, charTex);
        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, 1024, L.rows, 0, gl.RGBA, gl.UNSIGNED_BYTE, L.data);
        gl.bindTexture(gl.TEXTURE_2D, ringTex);
        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, L.R, 1, 0, gl.RGBA, gl.FLOAT, L.rings);
      }
      upload(SOURCE);
      codeEl.value = SOURCE;
    
      // ─── One photon, on the CPU ───────────────────────────────────────────────
      // The same integrator as the shader, in JavaScript, for the one pixel under
      // your cursor. It returns the whole path, so we can draw where the light
      // really went, and how far it was bent getting to you.
      function trace(o, d) {
        let [x0, x1, x2] = o, [v0, v1, v2] = d;
        const hx = x1 * v2 - x2 * v1, hy = x2 * v0 - x0 * v2, hz = x0 * v1 - x1 * v0;
        const h2 = hx * hx + hy * hy + hz * hz;
        const far = Math.max(Math.hypot(x0, x1, x2), R_GAS) + 1;
        const path = [[x0, x1, x2]];
        let bent = 0;
        for (let i = 0; i < MAX_STEPS; i++) {
          const r = Math.hypot(x0, x1, x2), sp = Math.hypot(v0, v1, v2);
          const dt = clamp(0.05 * r, 0.012, 4) / sp;
          const k = -1.5 * h2 / r ** 5;
          const y0 = x0 + v0 * dt + 0.5 * k * x0 * dt * dt;
          const y1 = x1 + v1 * dt + 0.5 * k * x1 * dt * dt;
          const y2 = x2 + v2 * dt + 0.5 * k * x2 * dt * dt;
          const rn = Math.hypot(y0, y1, y2), kn = -1.5 * h2 / rn ** 5;
          const w0 = v0 + 0.5 * (k * x0 + kn * y0) * dt;
          const w1 = v1 + 0.5 * (k * x1 + kn * y1) * dt;
          const w2 = v2 + 0.5 * (k * x2 + kn * y2) * dt;
          bent += Math.acos(clamp((v0 * w0 + v1 * w1 + v2 * w2) / (sp * Math.hypot(w0, w1, w2)), -1, 1));
          if (x1 * y1 < 0) {
            const f = x1 / (x1 - y1);
            const p = [x0 + (y0 - x0) * f, 0, x2 + (y2 - x2) * f];
            const rp = Math.hypot(p[0], p[2]);
            if (rp > R_IN && rp < R_GAS) {
              path.push(p);
              const dl = Math.hypot(w0, w1, w2);
              return { type: 'disk', p, dir: [w0 / dl, w1 / dl, w2 / dl], path, bent };
            }
          }
          x0 = y0; x1 = y1; x2 = y2; v0 = w0; v1 = w1; v2 = w2;
          path.push([x0, x1, x2]);
          if (rn < 1) return { type: 'horizon', path, bent };
          if (rn > far && x0 * v0 + x1 * v1 + x2 * v2 > 0) return { type: 'sky', path, bent };
        }
        return { type: 'orbit', path, bent };
      }
    
      // Which character of the file sits at disk point p, at this moment?
      function charAt(p) {
        const r = Math.hypot(p[0], p[2]);
        if (r >= R_TEXT) return null;
        const k = Math.floor((r - R_IN) / L.ringH), b = k * 4;
        const count = L.rings[b + 1];
        let s = -(Math.atan2(p[2], p[0]) - L.rings[b + 2] * diskTime) / TAU * count;
        s -= count * Math.floor(s / count);
        const idx = L.rings[b] + Math.floor(s);
        return idx < L.n ? idx : null;
      }
      function lineOf(off) {
        let lo = 0, hi = L.lineStarts.length - 1;
        while (lo < hi) { const m = (lo + hi + 1) >> 1; if (L.lineStarts[m] <= off) lo = m; else hi = m - 1; }
        return lo;
      }
      // Characters of the disk that came from a given line: a range, because the
      // disk preserves reading order.
      function streamRange(line) {
        const a = L.lineStarts[line], b = line + 1 < L.lineStarts.length ? L.lineStarts[line + 1] : Infinity;
        const first = (v) => { let lo = 0, hi = L.n; while (lo < hi) { const m = (lo + hi) >> 1; if (L.where[m] < v) lo = m + 1; else hi = m; } return lo; };
        return [first(a), first(b)];
      }
    
      // ─── Camera ───────────────────────────────────────────────────────────────
      const cam = { az: 0.6, el: 0.17, dist: 70 };
      const goal = { az: 0.6, el: 0.17, dist: 25 };
      let intro = true, lastInput = -1e9, engaged = !embedded;
      let basis = null, camPos = [0, 0, 0], tanY = 0.42;
    
      function updateCamera(dt, now) {
        if (now - lastInput > 7000) goal.az += dt * 0.025;       // drift when idle
        const kd = 1 - Math.exp(-dt * (intro ? 0.9 : 6));
        const ka = 1 - Math.exp(-dt * 6);
        cam.az += (goal.az - cam.az) * ka;
        cam.el += (goal.el - cam.el) * ka;
        cam.dist += (goal.dist - cam.dist) * kd;
        if (Math.abs(cam.dist - goal.dist) < 0.05) intro = false;
        const ce = Math.cos(cam.el);
        camPos = [cam.dist * ce * Math.cos(cam.az), cam.dist * Math.sin(cam.el), cam.dist * ce * Math.sin(cam.az)];
        const f = camPos.map((c) => -c / cam.dist);
        const rl = Math.hypot(f[2], f[0]);
        const r = [-f[2] / rl, 0, f[0] / rl];
        const u = [r[1] * f[2] - r[2] * f[1], r[2] * f[0] - r[0] * f[2], r[0] * f[1] - r[1] * f[0]];
        basis = { r, u, f };
        const aspect = ink.clientWidth / Math.max(1, ink.clientHeight);
        tanY = aspect >= 1.35 ? 0.42 : Math.min(1.1, 0.42 * 1.35 / aspect);
      }
    
      function rayThrough(px, py) {
        const w = ink.clientWidth, h = ink.clientHeight;
        const sx = (px / w * 2 - 1) * tanY * w / h, sy = (1 - py / h * 2) * tanY;
        const { r, u, f } = basis;
        const d = [0, 1, 2].map((i) => r[i] * sx + u[i] * sy + f[i]);
        const l = Math.hypot(...d);
        return d.map((c) => c / l);
      }
      function project(p) {
        const w = ink.clientWidth, h = ink.clientHeight, { r, u, f } = basis;
        const q = [p[0] - camPos[0], p[1] - camPos[1], p[2] - camPos[2]];
        const z = q[0] * f[0] + q[1] * f[1] + q[2] * f[2];
        if (z < 0.05) return null;
        const x = (q[0] * r[0] + q[1] * r[1] + q[2] * r[2]) / (z * tanY * w / h);
        const y = (q[0] * u[0] + q[1] * u[1] + q[2] * u[2]) / (z * tanY);
        return [(x + 1) / 2 * w, (1 - y) / 2 * h];
      }
    
      // ─── Input ────────────────────────────────────────────────────────────────
      const pointers = new Map();
      let probeAt = null, dragged = 0, pinch = 0, paused = false, editLine = -1;
    
      hintEl.innerHTML = touchy
        ? 'tap any light to trace it to its line of code · drag to orbit · pinch to fall in'
        : hintEl.innerHTML.replace('scroll to fall in', embedded ? 'click, then scroll to fall in' : 'scroll to fall in');
    
      canvas.addEventListener('pointerdown', (e) => {
        canvas.setPointerCapture(e.pointerId);
        pointers.set(e.pointerId, [e.clientX, e.clientY]);
        dragged = 0; engaged = true; intro = false; lastInput = performance.now();
        if (pointers.size === 2) { const [a, b] = [...pointers.values()]; pinch = Math.hypot(a[0] - b[0], a[1] - b[1]); }
      });
      canvas.addEventListener('pointermove', (e) => {
        const rect = canvas.getBoundingClientRect();
        if (!pointers.has(e.pointerId)) {
          if (e.pointerType === 'mouse') probeAt = [e.clientX - rect.left, e.clientY - rect.top];
          return;
        }
        const prev = pointers.get(e.pointerId);
        const dx = e.clientX - prev[0], dy = e.clientY - prev[1];
        pointers.set(e.pointerId, [e.clientX, e.clientY]);
        lastInput = performance.now();
        if (pointers.size === 2) {
          const [a, b] = [...pointers.values()];
          const d = Math.hypot(a[0] - b[0], a[1] - b[1]);
          if (pinch) goal.dist = clamp(goal.dist * pinch / d, 4.2, 90);
          pinch = d; dragged = 99;
          return;
        }
        dragged += Math.abs(dx) + Math.abs(dy);
        if (dragged > 4) {
          canvas.classList.add('drag');
          probeAt = null;
          goal.az += dx * 0.006;
          goal.el = clamp(goal.el + dy * 0.005, -1.45, 1.45);
        }
      });
      const release = (e) => {
        const rect = canvas.getBoundingClientRect();
        if (pointers.has(e.pointerId) && dragged <= 4 && e.type === 'pointerup') {
          probeAt = [e.clientX - rect.left, e.clientY - rect.top];
          if (e.pointerType === 'mouse' && hit && hit.line != null) openSource(hit.line);
        }
        pointers.delete(e.pointerId);
        if (pointers.size < 2) pinch = 0;
        canvas.classList.remove('drag');
      };
      canvas.addEventListener('pointerup', release);
      canvas.addEventListener('pointercancel', release);
      canvas.addEventListener('pointerleave', (e) => { if (e.pointerType === 'mouse' && !pointers.size) probeAt = null; });
      canvas.addEventListener('wheel', (e) => {
        if (!engaged) return;            // inside a post, let the page scroll until clicked
        e.preventDefault();
        intro = false; lastInput = performance.now();
        goal.dist = clamp(goal.dist * Math.exp(e.deltaY * (e.deltaMode ? 0.05 : 0.0012)), 4.2, 90);
      }, { passive: false });
    
      addEventListener('keydown', (e) => {
        if (e.target === codeEl) { if (e.key === 'Escape') closeSource(); return; }
        if (e.key === ' ') { paused = !paused; e.preventDefault(); }
        else if (e.key === 's' || e.key === 'S') srcEl.hidden ? openSource(hit && hit.line) : closeSource();
        else if (e.key === 'Escape') closeSource();
      });
    
      // ─── Source panel ─────────────────────────────────────────────────────────
      // Edit the file and the disk is rewritten as you type. The line under your
      // caret lights up wherever it is in orbit, including in its lensed images.
      function openSource(line) {
        srcEl.hidden = false;
        if (line == null) return;
        const a = L.lineStarts[line], b = (L.lineStarts[line + 1] || L.text.length + 1) - 1;
        codeEl.focus({ preventScroll: true });
        codeEl.setSelectionRange(a, b);
        const lh = parseFloat(getComputedStyle(codeEl).lineHeight) || 18;
        codeEl.scrollTop = Math.max(0, line * lh - codeEl.clientHeight / 3);
        editLine = line;
      }
      function closeSource() { srcEl.hidden = true; editLine = -1; codeEl.blur(); }
      $('open').onclick = () => openSource(null);
      $('close').onclick = closeSource;
      $('reset').onclick = () => { codeEl.value = SOURCE; upload(SOURCE); };
      let pending = 0;
      codeEl.addEventListener('input', () => {
        clearTimeout(pending);
        pending = setTimeout(() => { upload(codeEl.value); caret(); }, 120);
      });
      const caret = () => { if (L.text === codeEl.value) editLine = lineOf(codeEl.selectionStart); };
      for (const ev of ['keyup', 'click', 'select']) codeEl.addEventListener(ev, caret);
    
      // ─── Render targets, sized to the screen and to what the GPU can afford ──
      let quality = touchy ? 0.5 : 0.7, sceneT = null, chain = [], frameMs = 16, lastAdapt = 0;
      function resize() {
        const dpr = Math.min(devicePixelRatio || 1, 2);
        const w = Math.max(1, Math.round(canvas.clientWidth * dpr)), h = Math.max(1, Math.round(canvas.clientHeight * dpr));
        if (canvas.width !== w || canvas.height !== h) {
          canvas.width = ink.width = w; canvas.height = ink.height = h;
          sceneT = null;
        }
        const sw = Math.max(2, Math.round(w * quality)), sh = Math.max(2, Math.round(h * quality));
        if (!sceneT || sceneT.w !== sw || sceneT.h !== sh) {
          for (const t of [sceneT, ...chain]) if (t) { gl.deleteTexture(t.tex); gl.deleteFramebuffer(t.fb); }
          sceneT = target(sw, sh);
          chain = [];
          for (let i = 1, cw = sw, ch = sh; i <= 6 && Math.min(cw, ch) > 8; i++) {
            cw = Math.max(1, cw >> 1); ch = Math.max(1, ch >> 1);
            chain.push(target(cw, ch));
          }
        }
      }
      // If frames run long, trace fewer photons; if there is headroom, trace more.
      function adapt(dt, now) {
        frameMs += (dt * 1000 - frameMs) * 0.08;
        if (now - lastAdapt < 900) return;
        lastAdapt = now;
        if (frameMs > 24 && quality > 0.3) quality = Math.max(0.3, quality * 0.85);
        else if (frameMs < 17.5 && quality < 1) quality = Math.min(1, quality * 1.07);
      }
    
      function pass(prog, t, src, texel) {
        gl.bindFramebuffer(gl.FRAMEBUFFER, t ? t.fb : null);
        gl.viewport(0, 0, t ? t.w : canvas.width, t ? t.h : canvas.height);
        gl.useProgram(prog.p);
        if (src) {
          gl.activeTexture(gl.TEXTURE0);
          gl.bindTexture(gl.TEXTURE_2D, src.tex);
          gl.uniform1i(prog.u.uTex, 0);
          gl.uniform2f(prog.u.uTexel, 1 / src.w, 1 / src.h);
        }
        gl.drawArrays(gl.TRIANGLES, 0, 3);
      }
    
      let diskTime = 0, hi = [0, 0];
      function render(now) {
        const u = scene.u, { r, u: up_, f } = basis;
        gl.useProgram(scene.p);
        gl.uniform2f(u.uRes, sceneT.w, sceneT.h);
        gl.uniform3f(u.uCam, ...camPos);
        gl.uniformMatrix3fv(u.uBasis, false, [...r, ...up_, ...f]);
        gl.uniform1f(u.uTan, tanY);
        gl.uniform1f(u.uTime, diskTime);
        gl.uniform1f(u.uRingH, L.ringH);
        gl.uniform1f(u.uCols, COLS);
        gl.uniform2f(u.uCell, 1 / COLS, 1 / atlasRows);
        gl.uniform1f(u.uCellPx, CELL_H);
        gl.uniform1f(u.uStore, STORE);
        gl.uniform2i(u.uHi, hi[0], hi[1]);
        [atlasTex, charTex, ringTex].forEach((t, i) => {
          gl.activeTexture(gl.TEXTURE0 + i);
          gl.bindTexture(gl.TEXTURE_2D, t);
        });
        gl.uniform1i(u.uAtlas, 0); gl.uniform1i(u.uChars, 1); gl.uniform1i(u.uRings, 2);
        pass(scene, sceneT);
    
        pass(down, chain[0], sceneT);
        for (let i = 1; i < chain.length; i++) pass(down, chain[i], chain[i - 1]);
        gl.enable(gl.BLEND); gl.blendFunc(gl.ONE, gl.ONE);
        for (let i = chain.length - 1; i > 0; i--) pass(up, chain[i - 1], chain[i]);
        gl.disable(gl.BLEND);
    
        gl.useProgram(final.p);
        gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, sceneT.tex);
        gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, chain[0].tex);
        gl.uniform1i(final.u.uScene, 0); gl.uniform1i(final.u.uBloom, 1);
        gl.uniform1f(final.u.uInv, 1 / STORE);
        gl.uniform1f(final.u.uBloomK, 0.07);
        gl.uniform1f(final.u.uSeed, now % 1000);
        pass(final, null);
      }
    
      // ─── The probe ────────────────────────────────────────────────────────────
      // Follow the photon under the cursor back to its source and say what
      // happened to it on the way.
      let hit = null;
      const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
      const deg = (a) => Math.round(a * 180 / Math.PI) + '°';
    
      function probe() {
        const w = ink.width, h = ink.height, s = w / Math.max(1, ink.clientWidth);
        pen.setTransform(1, 0, 0, 1, 0, 0);
        pen.clearRect(0, 0, w, h);
        hit = null;
        hi = editLine >= 0 && !srcEl.hidden ? streamRange(editLine) : [0, 0];
        if (!probeAt) { probeEl.hidden = true; return; }
    
        const res = trace(camPos, rayThrough(...probeAt));
        hit = res;
        probeEl.replaceChildren();
        let head = '', ln = null, phys = '', note = '';
    
        if (res.type === 'disk') {
          const p = res.p, r = Math.hypot(p[0], p[2]), phi = Math.atan2(p[2], p[0]);
          const beta = Math.sqrt(0.5 / (r - 1)), gamma = 1 / Math.sqrt(1 - beta * beta);
          const cosT = -(-Math.sin(phi) * res.dir[0] + Math.cos(phi) * res.dir[2]);
          const g = Math.sqrt(1 - 1 / r) / (gamma * (1 - beta * cosT));
          phys = `r = ${r.toFixed(2)} rₛ · gas at ${beta.toFixed(2)}c · ` +
            (g >= 1 ? `blueshift ×${g.toFixed(2)}` : `redshift z = ${(1 / g - 1).toFixed(2)}`) +
            ` · clocks at ${Math.round(100 * Math.sqrt(1 - 1.5 / r))}%`;
          const idx = charAt(p);
          if (idx != null) {
            const off = L.where[idx], line = lineOf(off), start = L.lineStarts[line];
            const raw = L.text.slice(start, (L.lineStarts[line + 1] || L.text.length + 1) - 1);
            const col = off - start;
            res.line = line;
            hi = streamRange(line);
            head = `line <b>${line + 1}</b> · col ${col + 1} · ${L.lang(off)}`;
            const lead = raw.length - raw.trimStart().length;
            const a = Math.max(lead, Math.min(col - 24, raw.length - 56)), b = Math.min(raw.length, a + 56);
            const c = clamp(col, a, b);
            ln = el('div', 'ln');
            ln.append((a > lead ? '…' : '') + raw.slice(a, c), el('i', '', raw[c] && raw[c].trim() ? raw[c] : '·'),
              raw.slice(c + 1, b) + (b < raw.length ? '…' : ''));
          } else {
            head = r >= R_TEXT ? 'gas beyond the first line' : 'the end of the file';
          }
          const behind = p[0] * camPos[0] + p[2] * camPos[2] < 0;
          if (res.bent > 1.5 * Math.PI) note = `A higher-order image. This light wrapped around the hole (bent ${deg(res.bent)}) before it reached you. The same text appears here and elsewhere.`;
          else if (behind && res.bent > 0.6) note = `This text is behind the black hole. You can see it only because its light was bent ${deg(res.bent)} around it. The line marks where it really is.`;
          else if (res.bent > 0.35) note = `Light from here was bent ${deg(res.bent)} on its way to you.`;
          else note = `Light from here reaches you almost straight: bent ${deg(res.bent)}.`;
        } else if (res.type === 'horizon') {
          head = 'the shadow';
          note = `No light comes back from here. The shadow is ${SHADOW.toFixed(2)}× wider than the horizon itself, because any ray aimed closer than ${SHADOW.toFixed(2)} rₛ spirals in.`;
        } else if (res.type === 'orbit') {
          head = 'the photon sphere';
          note = 'This light is still circling at 1.5 rₛ, where gravity is strong enough to hold light in orbit.';
        } else {
          head = 'starlight';
          note = res.bent > 0.08
            ? `A star behind you or beside the hole, its light bent ${deg(res.bent)}. Near the shadow the whole sky folds around.`
            : 'A distant star, almost undisturbed.';
        }
        const k = el('div', 'k'); k.innerHTML = head;
        probeEl.append(k);
        if (ln) probeEl.append(ln);
        if (phys) probeEl.append(el('div', 'ph', phys));
        probeEl.append(el('div', 'note', note));
        probeEl.hidden = false;
    
        // Place the card beside the cursor, kept on screen.
        const cw = ink.clientWidth, ch = ink.clientHeight, bw = probeEl.offsetWidth, bh = probeEl.offsetHeight;
        let x = probeAt[0] + 18, y = probeAt[1] + 18;
        if (x + bw > cw - 8) x = probeAt[0] - bw - 18;
        if (y + bh > ch - 8) y = probeAt[1] - bh - 18;
        probeEl.style.left = clamp(x, 8, cw - bw - 8) + 'px';
        probeEl.style.top = clamp(y, 8, ch - bh - 8) + 'px';
    
        // Draw the photon's path as if light went straight: it starts under the
        // cursor and curls away to wherever the light actually came from.
        pen.setTransform(s, 0, 0, s, 0, 0);
        pen.lineWidth = 1.2;
        pen.strokeStyle = 'rgba(143, 214, 255, 0.85)';
        pen.shadowColor = 'rgba(143, 214, 255, 0.9)';
        pen.shadowBlur = 8;
        pen.beginPath();
        let open = false;
        for (const q of res.path) {
          const sp = project(q);
          if (!sp || Math.abs(sp[0]) > 1e5 || Math.abs(sp[1]) > 1e5) { open = false; continue; }
          open ? pen.lineTo(sp[0], sp[1]) : pen.moveTo(sp[0], sp[1]);
          open = true;
        }
        pen.stroke();
        pen.shadowBlur = 0;
        pen.beginPath(); pen.arc(probeAt[0], probeAt[1], 5, 0, TAU); pen.stroke();
        if (res.type === 'disk') {
          const sp = project(res.p);
          if (sp) {
            pen.fillStyle = '#8fd6ff';
            pen.beginPath(); pen.arc(sp[0], sp[1], 3, 0, TAU); pen.fill();
            if (Math.hypot(sp[0] - probeAt[0], sp[1] - probeAt[1]) > 40) {
              pen.font = '11px ui-monospace, Menlo, Consolas, monospace';
              pen.fillText('emitted here', sp[0] + 7, sp[1] - 7);
            }
          }
        }
      }
    
      // ─── Loop ─────────────────────────────────────────────────────────────────
      let visible = true, last = performance.now();
      if ('IntersectionObserver' in window) new IntersectionObserver((es) => { visible = es[0].isIntersecting; }).observe(canvas);
      function frame(now) {
        requestAnimationFrame(frame);
        if (!visible || document.hidden) { last = now; return; }
        const dt = Math.min(0.1, (now - last) / 1000);
        last = now;
        if (!paused) diskTime += dt * SPIN;
        updateCamera(dt, now);
        adapt(dt, now);
        resize();
        probe();
        render(now);
      }
      requestAnimationFrame(frame);
    
      // Exposed for the curious, in the console.
      window.accretion = { trace, get layout() { return L; }, get camera() { return cam; }, goal,
        set time(t) { diskTime = t; }, get time() { return diskTime; }, set quality(q) { quality = q; },
        probe: (x, y) => { probeAt = [x, y]; } };
    }
    
    if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot);
    else boot();
    })();
    </script>
    <!--
      This is the end of the file, so it orbits closest. Three Schwarzschild
      radii is the innermost stable circular orbit: any further in and no orbit
      holds, there is only falling. Here the gas moves at half the speed of light,
      a clock riding with it runs at seventy-one percent of yours, and the light
      these words give off is bent so hard that some of it comes back around to
      you from the far side of the hole. Everything you read on the way in was
      arriving here.
    -->
    </body>
    </html>
    

    result, 1 line

    File created successfully at: ~/run/accretion.html (file state is current in your context — no need to Read it back)

agent

+12:15

Now let me render it headlessly to check it compiles and looks right.

  • Bashcd /tmp/pw && cat > shot.mjs <<'EOF'

    command

    cd /tmp/pw && cat > shot.mjs <<'EOF'
    import puppeteer from 'puppeteer';
    const [,, out='/tmp/pw/a.png', setup='', w='1200', h='700'] = process.argv;
    const b = await puppeteer.launch({headless:'new', args:['--use-angle=swiftshader','--enable-unsafe-swiftshader','--ignore-gpu-blocklist']});
    const p = await b.newPage();
    await p.setViewport({width:+w, height:+h, deviceScaleFactor:1});
    const logs=[]; p.on('console', m=>logs.push(m.type()+': '+m.text())); p.on('pageerror', e=>logs.push('ERR '+e.message));
    await p.goto('file://~/run/accretion.html');
    await new Promise(r=>setTimeout(r,1500));
    if (setup) await p.evaluate(setup);
    await new Promise(r=>setTimeout(r,9000));
    await p.screenshot({path: out});
    console.log(logs.join('\n'));
    console.log(await p.evaluate(()=>{const L=accretion.layout; return JSON.stringify({n:L.n,R:L.R,ringH:L.ringH,glyphs:L.glyphs.length, cam:accretion.camera})}));
    await b.close();
    EOF
    node shot.mjs /tmp/pw/a.png "accretion.camera.dist=25; accretion.quality=0.6"

    result, 2 lines

    {"n":40209,"R":71,"ringH":0.15492957746478872,"glyphs":103,"cam":{"az":0.6115514175960243,"el":0.17,"dist":25}}
    Shell cwd was reset to ~/run
  • Read/tmp/pw/a.png

    input

    {
      "file_path": "/tmp/pw/a.png"
    }

    result

    no output

    a.jpg
    a.jpg

agent

+13:16
reasoning

It compiles and renders correctly on the first run, but the look needs tuning: too many stars, a dull beige disk, and the hole is too small. I'm tuning those now.

  • Bashpython3 - <<'EOF'

    command

    python3 - <<'EOF'
    import re
    f='~/run/accretion.html'; s=open(f).read()
    old_sky=s[s.index('  for (int l = 0; l < 3; l++) {\n    float sc = 45.0'):s.index('  vec3 n = normalize(vec3(0.25')]
    new_sky='''  for (int l = 0; l < 3; l++) {
        float sc = 30.0 * pow(2.0, float(l));
        vec3 id = floor(d * sc);
        vec3 h = hash33(id + float(l) * 71.0);
        if (h.x < 0.86) continue;                      // most cells are empty
        vec3 s = normalize(id + 0.5 + (h - 0.5) * 0.7);
        float dist = length(d - s) / max(pix, 1e-4);
        float lum = pow(h.y, 6.0) * 2.2 / (1.0 + float(l) * 1.5);
        c += lum * exp(-dist * dist * 2.0) * mix(vec3(1.0, 0.72, 0.5), vec3(0.65, 0.8, 1.0), h.z);
      }
    '''
    s=s.replace(old_sky,new_sky)
    s=s.replace('c += band * noise(d * 5.0) * noise(d * 13.0) * vec3(0.05, 0.035, 0.05);','c += band * noise(d * 5.0) * noise(d * 13.0) * vec3(0.022, 0.016, 0.024);')
    s=s.replace('''  float T = 8200.0 * pow(r / R_IN, -0.6) * g;
      float I = pow(r / R_IN, -1.45) * pow(g, 3.0);''','''  float T = 9500.0 * pow(r / R_IN, -0.75) * g;
      float I = 2.4 * pow(r / R_IN, -2.0) * pow(g, 3.0);''')
    s=s.replace('float gas = 0.05 + 0.11 * noise(vec3(q * 1.7, r * 3.0)) * noise(vec3(q * 0.4, r * 9.0) + 7.0);',
     'float gas = 0.16 + 0.42 * noise(vec3(q * 1.7, r * 3.0)) * noise(vec3(q * 0.35, r * 7.0) + 7.0);')
    s=s.replace('float alpha = clamp((0.42 + 0.55 * cov) * fade, 0.0, 1.0);','float alpha = clamp((0.82 + 0.18 * cov) * fade, 0.0, 1.0);')
    s=s.replace("const goal = { az: 0.6, el: 0.17, dist: 25 };","const goal = { az: 0.6, el: 0.17, dist: 21 };")
    open(f,'w').write(s)
    EOF
    cd /tmp/pw && node shot.mjs /tmp/pw/a.png "accretion.camera.dist=21; accretion.quality=0.6"

    result, 2 lines

    {"n":40273,"R":71,"ringH":0.15492957746478872,"glyphs":103,"cam":{"az":0.6629340413578153,"el":0.17,"dist":21}}
    Shell cwd was reset to ~/run
  • Read/tmp/pw/a.png

    input

    {
      "file_path": "/tmp/pw/a.png"
    }

    result

    no output

    a_2.jpg
    a_2.jpg

agent

+13:48

The blockiness comes from the adaptive-resolution logic reacting to the slow software renderer. I'll pin the quality in the test harness so I can judge the real image.

  • Bashcd /tmp/pw && sed -i 's#if (setup) await p.evaluate(setup);#await p.evaluate("setInterval(()=>accretion.quality=window.__q||0.75,50)"); if (setup) await p.evaluate(setup);#' shot.mjs && node shot.mjs /tmp/pw/a.png "accretion.camera.dist=21"

    command

    cd /tmp/pw && sed -i 's#if (setup) await p.evaluate(setup);#await p.evaluate("setInterval(()=>accretion.quality=window.__q||0.75,50)"); if (setup) await p.evaluate(setup);#' shot.mjs && node shot.mjs /tmp/pw/a.png "accretion.camera.dist=21"

    result, 2 lines

    {"n":40273,"R":71,"ringH":0.15492957746478872,"glyphs":103,"cam":{"az":0.633212984028869,"el":0.17,"dist":21}}
    Shell cwd was reset to ~/run
  • Read/tmp/pw/a.png

    input

    {
      "file_path": "/tmp/pw/a.png"
    }

    result

    no output

    a_3.jpg
    a_3.jpg