In this section
- Wafer Development Environment — Proof K0010 Page render · globalgrid2050 / testcode/wafer-development-environment/202609191800-proof-k0010/index.html lines 700–724
- Wafer Development Environment — Proof K0014 Page render · globalgrid2050 / testcode/wafer-development-environment/202609192001-proof-k0014/index.html lines 1–675
Wafer Development Environment — Proof K0010 Page
A web page in the testcode folder of GlobalGrid2050 that converts to world (`toWorld`), steps anim (`stepAnim`), loads tracked (`loadTracked`) and calculates planar distances. Published at https://globalgrid2050.com/testcode/wafer-development-environment/202609191800-proof-k0010/.
renderglobalgrid2050 / testcode/wafer-development-environment/202609191800-proof-k0010/index.html · lines 700–724 of 724 · version 2026-09-19 18:00 (continued from section 1473) · Entry point · pattern loadTracked (shared by 16 files)
- What it does
- It draws its content. Defines 45 functions or classes, including fmt, words, prog, U, tsv. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Inputs & outputs
- In: form fields (user input). Out: web page; WebGL/WebGPU drawing.
- Downstream impact
- Used directly by 5 files: GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage Versions — Before Refresh Page (globalgrid2050, https://globalgrid2050.com/homepage_versions/20260922-before-refresh/); Homepage V123 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v123.html); Homepage V124 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v124.html); and 1 more. Reached from 83 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); Homepage V037 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v037.html); Homepage V038 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v038.html). It is itself an entry point, published at https://globalgrid2050.com/testcode/wafer-development-environment/202609191800-proof-k0010/.
- What it achieves
- It shows new (`showNew`) and loads tracked (`loadTracked`). Its `lightTime` function gives commit period summary or null from year, optional month and optional day (VEDIC: period). It responds to webglcontextlost, resize and pointerdown events.
- Why it matters
- Loaded by the GlobalGrid2050 Homepage Before Four Nests page at https://globalgrid2050.com/homepage-before-four-nests-20260925.html and 4 other pages.
- Application
- globalgrid2050 · testcode/wafer-development-environment/202609191800-proof-k0010 · page
- VEDIC
- PERIOD (GG2050-VEDIC-000042): Kuiper / Code navigation · Computer science / Interactive visualisation. year, month_optional, day_optional, ordered_commits → commit_period_summary_or_null
- Uses
- none found
- Used by
- linked from GlobalGrid2050 Homepage Before Four Nests (link), linked from Homepage Versions — Before Refresh Page (link), linked from Homepage V123 (link), linked from Homepage V124 (link), linked from Homepage V125 (link)
- Produces
- fmt, words, prog, U, tsv, narrow, resize, flyTo, layout, safeBox, homeCamera, home
- Defines here
- none
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/wafer-development-environment/202609191800-proof-k0010/index.html:700-724 · blob 3f5b12f8d6406559640c98b8233c505ea9c131e6 · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
// the tap targets, so a phone can do everything the keyboard can
document.getElementById('keys').addEventListener('click', e => { const k = e.target.getAttribute('data-k'); if (!k) return;
e.stopPropagation(); dispatchEvent(new KeyboardEvent('keydown', { key:k })); });
elTop.addEventListener('click', () => elTop.classList.toggle('open')); // the long subtitle, collapsed by default
card.addEventListener('click', () => { card.style.display = 'none'; dirty = true; });
const gbox = document.getElementById('goto'), gin = document.getElementById('gotoin');
gin.addEventListener('keydown', e => { e.stopPropagation(); if (e.key === 'Escape') { gbox.style.display = 'none'; return; }
if (e.key !== 'Enter') return; gbox.style.display = 'none'; const raw = gin.value.trim(), q = raw.replace(/[ ,_]/g,'');
const mt = raw.match(/^(20\d\d)(?:-(\d\d))?(?:-(\d\d))?$/);
if (mt) { lightTime(+mt[1], mt[2] ? +mt[2] : 0, mt[3] ? +mt[3] : 0); return; }
const mnew = raw.toLowerCase().match(/^(?:show\s+)?new(?:\s+code)?(?:\s+(\d+)\s*h?)?$/);
if (mnew) { showNew(mnew[1] ? Number(mnew[1]) : 24); return; }
if (/^\d+$/.test(q)) goKey(Math.min(SPACE-1, Number(q)));
else { const r = repos.find(x => x.name.toLowerCase() === raw.toLowerCase()) || repos.find(x => x.name.toLowerCase().includes(raw.toLowerCase()));
if (r) { litRepo = r.i; target = null; card.style.display = 'none'; home(); dirty = true; } } });
addEventListener('keydown', e => { if (gbox.style.display === 'block') return;
if (e.key === 'd') { detail = !detail; dirty = true; }
else if (e.key === 'r' && N) { const j = Math.floor(Math.random()*N), c = commits[findBy('cum', j)]; goKey(c.k0 + (j - c.cum)); } // uniform over issued lines
else if (e.key === 'n' && N) showNew(24);
else if (e.key === '/') { e.preventDefault(); gbox.style.display = 'block'; gin.value = ''; gin.focus(); }
else if (e.key === 'Backspace') { e.preventDefault(); target = null; litRepo = -1; newFrom = -1; flash = 0; pulse = -1; litK = [-1,-1]; litCi = null; litPath = null; card.style.display = 'none'; home(); } });
requestAnimationFrame(frame);
</script>
</body>
</html>Wafer Development Environment — Proof K0014 Page
A web page in the testcode folder of GlobalGrid2050 that converts to world (`toWorld`), renders code (`renderCode`), steps anim (`stepAnim`) and calculates planar distances. Published at https://globalgrid2050.com/testcode/wafer-development-environment/202609192001-proof-k0014/.
Set aside from the main view: 95% of its lines are the same as testcode/wafer-development-environment/202609192016-proof-k0015/index.html (globalgrid2050), which stays. (near-copy-of, proposed by families.py). 94% of lines shared with Wafer Development Environment — Proof K0015 Page; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9486 to globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/wafer-development-environment/202609192016-proof-k0015/index.html:1-986 0f37a8bb2a6ddb5a0fa16f2ec414b1af995ca61b
- sha256 afd5af2d1f7e007d63902e6516fe63d8a2fbff1f20f1bae310799c35a4b4578a
- target sha256 a5106031252f46eff3699a28a7b914ec4f458a94a0cbbf95a377ca417574c0d4
- group of 2 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
renderglobalgrid2050 / testcode/wafer-development-environment/202609192001-proof-k0014/index.html · lines 1–675 of 942 · version 2026-09-19 20:01 · Entry point · pattern renderCode (shared by 3 files)
- What it does
- It draws its content. Defines 57 functions or classes, including fmt, day, words, prog, U. Side effects: changes the web page (DOM); makes network requests.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Inputs & outputs
- In: form fields (user input). Out: web page; WebGL/WebGPU drawing.
- Downstream impact
- Used directly by 5 files: GlobalGrid2050 Homepage Before Four Nests (globalgrid2050, https://globalgrid2050.com/homepage-before-four-nests-20260925.html); Homepage Versions — Before Refresh Page (globalgrid2050, https://globalgrid2050.com/homepage_versions/20260922-before-refresh/); Homepage V123 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v123.html); Homepage V124 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v124.html); and 1 more. Reached from 83 other entry points, including GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html); Homepage V037 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v037.html); Homepage V038 (globalgrid2050, https://globalgrid2050.com/homepage_versions/homepage_v038.html). It is itself an entry point, published at https://globalgrid2050.com/testcode/wafer-development-environment/202609192001-proof-k0014/.
- What it achieves
- It renders code (`renderCode`), shows new (`showNew`) and loads tracked (`loadTracked`). Its `lightTime` function gives commit period summary or null from year, optional month and optional day (VEDIC: period). It responds to webglcontextlost, resize and pointerdown events.
- Why it matters
- Loaded by the GlobalGrid2050 Homepage Before Four Nests page at https://globalgrid2050.com/homepage-before-four-nests-20260925.html and 4 other pages.
- Application
- globalgrid2050 · testcode/wafer-development-environment/202609192001-proof-k0014 · page
- VEDIC
- PERIOD (GG2050-VEDIC-000042): Kuiper / Code navigation · Computer science / Interactive visualisation. year, month_optional, day_optional, ordered_commits → commit_period_summary_or_null
- Uses
- none found
- Used by
- linked from GlobalGrid2050 Homepage Before Four Nests (link), linked from Homepage Versions — Before Refresh Page (link), linked from Homepage V123 (link), linked from Homepage V124 (link), linked from Homepage V125 (link)
- Produces
- fmt, day, words, prog, U, tsv, narrow, resize, flyTo, layout, safeBox, homeCamera
- Defines here
- fmt, day, words, prog, U, tsv, narrow, resize, flyTo, layout, safeBox, homeCamera, home, keyPlace, findBy, address, describe, issuedBelow, ownerAt, widestRunPx, span, linesByRunningTotals, keyAt, frame, draw, read, toWorld, cardFor, esc, gh
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/wafer-development-environment/202609192001-proof-k0014/index.html:1-675 · blob 16f1f415f9f91296048e1713e4a5a8215067d26b · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: production_core
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>Kuiper belt</title>
<style>
:root{--bg:#090c13;--ink:#d5dcea;--dim:#7d8799;--line:#1a2030;--hot:#e8b36a}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);
font:12px/1.55 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;overflow:hidden;
overscroll-behavior:none;-webkit-text-size-adjust:100%}
canvas{position:fixed;inset:0;width:100%;height:100%;display:block;touch-action:none}
#c{z-index:1} #o{z-index:3;pointer-events:none}
#top{position:fixed;top:0;left:0;padding:10px 14px;z-index:10;pointer-events:none;max-width:60vw;background:#090c13d9;border-bottom-right-radius:6px}
#big{font-size:19px;letter-spacing:.03em} #sub{color:var(--dim);margin-top:2px}
#hud{position:fixed;top:0;right:0;padding:10px 14px;z-index:10;color:var(--dim);text-align:right;white-space:pre-line;max-width:38vw;background:#090c13d9;border-bottom-left-radius:6px}
#card{position:fixed;left:14px;bottom:64px;z-index:10;color:var(--ink);background:#090c13ee;
border:1px solid var(--line);padding:9px 12px;white-space:pre-line;display:none;max-width:min(680px,92vw)}
#card b{color:var(--hot);font-weight:600}
/* THE CODE SHEET. Three parts that do not move relative to one another: where this line lives,
the code, and where to go to see it in its own repository. Only the middle one scrolls. */
#card.sheet{display:flex;flex-direction:column;white-space:normal;padding:0;max-height:min(60vh,560px)}
#card.sheet .ch{flex:0 0 auto;padding:8px 12px 6px;border-bottom:1px solid #12414a;overflow-wrap:anywhere}
#card.sheet .cb{flex:1 1 auto;min-height:0;overflow-y:auto;overflow-x:hidden;padding:6px 12px}
#card.sheet .cf{flex:0 0 auto;padding:8px 12px;border-top:1px solid #12414a;background:#0b1016}
/* LONG LINES WRAP. They used to be cut at the right edge with nothing to say they went on, which
is a page hiding words from a reader. The number keeps its own column so a wrapped line still
reads as one line. */
#card.sheet .cl{display:grid;grid-template-columns:5ch 1fr;gap:8px}
#card.sheet .cl .ln{color:#4e5a66;text-align:right}
#card.sheet .cl .tx{white-space:pre-wrap;overflow-wrap:anywhere}
#card.sheet .cl.hit .tx{color:var(--am);font-weight:600}
#card.sheet .cl.hit .ln{color:var(--am)}
#use{margin-top:5px;color:#8fb3bd;max-width:62ch}
#foot .short{display:none}
#foot,#foot span{overflow-wrap:anywhere}
#foot{position:fixed;left:0;right:0;bottom:0;padding:8px 14px;color:var(--dim);border-top:1px solid var(--line);
background:#090c13ee;z-index:10;line-height:1.7}
#foot b{color:var(--ink);font-weight:600} a{color:#66ccff}
#goto{position:fixed;left:50%;top:38%;transform:translateX(-50%);z-index:20;display:none;background:var(--bg);
border:1px solid var(--dim);padding:10px 12px;min-width:min(520px,86vw)}
#goto input{width:100%;background:var(--bg);color:var(--ink);border:0;outline:0;font:14px ui-monospace,Consolas,monospace}
/* SCADA MEANINGS, one colour one meaning: x-ray grey is the record, cyan is the instrument,
green is energised (lit), amber is attention (new), magenta is selected. */
:root{--cy:#2ee6e6;--gn:#22ee77;--am:#ffb000;--mg:#ff2bd6}
#big{color:var(--cy);text-transform:uppercase;letter-spacing:.16em;font-size:15px}
#top,#hud{border:1px solid #12414a;border-top:0} #top{border-left:0} #hud{border-right:0;color:#8fb3bd}
#card{border-color:#1d6470} #card b{color:var(--am)} #foot{border-top-color:#12414a} #foot b{color:var(--cy)}
#goto{border-color:var(--cy)}
/* THE PHONE. These are read on an iPhone in portrait. Nothing fixed may sit over the wafer, so
on a narrow screen every panel becomes a full width strip at the top or the bottom and the
camera is given the rectangle that is left (safeBox in the script). The long subtitle would
eat a third of the screen, so it collapses and opens on a tap; nothing is deleted. The
keyboard commands get tap targets, because a phone has no n, no r and no slash. */
#keys{display:flex;gap:6px;flex-wrap:wrap;margin-bottom:6px}
#keys button{background:#0b1a20;color:#8fb3bd;border:1px solid #12414a;padding:7px 10px;font:inherit;
text-transform:uppercase;letter-spacing:.06em;cursor:pointer;touch-action:manipulation}
#keys button:hover,#keys button:active{border-color:var(--cy);color:var(--cy)}
#top{cursor:pointer}
@media (max-width:640px){
html,body{font-size:11px}
#top,#hud{left:0;right:0;max-width:none;border-radius:0;border-left:0;border-right:0;padding:7px 10px}
#hud{text-align:left;border-right:0}
#big{font-size:13px;letter-spacing:.10em}
#sub{max-height:0;overflow:hidden;margin-top:0}
#top.open #sub{max-height:38vh;overflow:auto;margin-top:4px}
#card{left:8px;right:8px;max-width:none;max-height:34vh;overflow:auto}
#card.sheet{left:0;right:0;max-height:min(58vh,480px);overflow:hidden}
#card.sheet .ch,#card.sheet .cb,#card.sheet .cf{padding-left:10px;padding-right:10px}
#foot{padding:7px 10px}
#foot .long{display:none} #foot .short{display:block;margin-top:6px}
#keys button{padding:9px 11px}
#goto{min-width:0;left:8px;right:8px;transform:none;top:30%}
}
</style>
</head>
<body>
<canvas id="c"></canvas><canvas id="o"></canvas>
<div id="top"><div id="big">loading</div><div id="sub"> </div>
<div id="use">The engineering behind this site: every calculation, drawing and data set, in the order it was built. Tap a dot to see the work and its date. Not a design and not a connection offer.</div></div>
<div id="hud">starting</div>
<div id="card"></div>
<div id="goto"><input id="gotoin" autocomplete="off" spellcheck="false" placeholder="a key, or a repository name to send light through"></div>
<div id="foot">
<div id="keys"><button data-k="n">new code</button><button data-k="r">random line</button><button
data-k="/">find</button><button data-k="Backspace">whole view</button></div>
<span class="long"><b>tap a dot</b> to light its repository · <b>drag</b> to move · <b>pinch or scroll</b> to zoom
· <b>n</b> new code · <b>r</b> random line · <b>/</b> find a key, a repository or a month
· <b>backspace</b> whole view · provided as is, without warranty of any kind; a chart, not a design</span>
<span class="short">provided as is, without warranty of any kind; a chart, not a design</span>
</div>
<script type="module">
// THE KUIPER BELT AS ONE WAFER. Every line in every file in every commit, one key each, in the
// order time issued them.
//
// THE LAW, and there is only one, at every zoom:
// key k -> r = sqrt(k), theta = 2 pi frac(k G / 2^32), G = 2654435769
// It inverts, k = r squared, so the number of keys in any annulus is arithmetic. Nothing is ever
// drawn 38,000 times into a pixel to discover a number the law already states.
//
// THE RINGS ARE TIME. Before each commit a run of keys is left UNISSUED in proportion to the
// silence since the commit before it (tools/wafer_keys.py, a declared constant). A night is a dark
// ring. The dark fraction of every pixel is computed exactly from a prefix sum of issued keys, so
// even the rings are arithmetic. A line not yet written already has its place, on the rim, the
// way an address in RAM exists before anything is stored at it.
//
// UNRESOLVED pixels state a computed count as a shade. RESOLVED fields draw exactly the issued keys
// whose radius can be on screen, each at its own place. There is no sampling and no white flash,
// because a pixel is never asked to be more than it is.
const G32 = 2654435769, TW = 4096;
const cv = document.getElementById('c'), ov = document.getElementById('o'), o2 = ov.getContext('2d');
const gl = cv.getContext('webgl2', { antialias:false, alpha:false, powerPreference:'high-performance' });
const hud = document.getElementById('hud'), big = document.getElementById('big'),
sub = document.getElementById('sub'), card = document.getElementById('card');
const fmt = n => Math.round(n).toLocaleString('en-GB');
// A DAY A PERSON CAN READ. Every date on this page comes through here, so the card header and
// the readout can never disagree about how a day is written.
const MON = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
function day(unix){ if (!unix) return ''; const t = new Date(unix * 1000);
return t.getUTCDate() + ' ' + MON[t.getUTCMonth()] + ' ' + t.getUTCFullYear(); }
function words(n){ if (n >= 1e9) return (n/1e9).toFixed(2)+' billion'; if (n >= 1e6) return (n/1e6).toFixed(2)+' million';
if (n >= 1e3) return (n/1e3).toFixed(1)+' thousand'; return n >= 10 ? n.toFixed(0) : n.toFixed(2); }
if (!gl) { hud.textContent = 'WebGL2 is not available. Refusing rather than drawing a fraction.'; throw 0; }
const VS_FULL = `#version 300 es
void main(){ vec2 p = vec2(float((gl_VertexID<<1)&2), float(gl_VertexID&2)); gl_Position = vec4(p*2.0-1.0,0.0,1.0); }`;
const FS_FIELD = `#version 300 es
precision highp float; precision highp sampler2D;
uniform vec2 u_res, u_center; uniform float u_zoom, u_R, u_points;
uniform sampler2D u_commits; uniform int u_n, u_litRepo; uniform float u_pulse, u_flash, u_newR; uniform vec2 u_litK;
uniform sampler2D u_pathf; uniform int u_litPath; // one texel per commit: did this page's path change in it
out vec4 o;
vec4 C(int i){ return texelFetch(u_commits, ivec2(i % ${TW}, i / ${TW}), 0); } // k0, k1, issued before, repo
int find(float k){ int lo = 0, hi = u_n - 1;
for (int s = 0; s < 16; ++s){ if (lo >= hi) break; int m = (lo+hi+1)/2; if (C(m).r <= k) lo = m; else hi = m-1; } return lo; }
// how many ISSUED keys lie below address k: a prefix sum, so any annulus is one subtraction
float issuedBelow(float k){ vec4 c = C(find(k)); return c.b + clamp(k - c.r, 0.0, c.g - c.r); }
void main(){
vec2 w = u_center + (gl_FragCoord.xy - 0.5*u_res) / u_zoom;
float r = length(w), h = 0.75 / u_zoom;
vec3 bg = vec3(0.035,0.047,0.075), dust = vec3(0.79,0.83,0.90);
if (r > u_R + h) { float rim = smoothstep(2.5/u_zoom, 0.0, abs(r - u_R)); o = vec4(bg + rim*0.10, 1.0); return; }
float ka = max(r-h, 0.0), kb = r+h; ka *= ka; kb *= kb;
float cov = clamp((issuedBelow(kb) - issuedBelow(ka)) / max(kb - ka, 1.0), 0.0, 1.0); // issued share of this pixel
float perPx = cov / (3.14159265 * u_zoom * u_zoom); // issued keys in this pixel
float v = (u_points > 0.5) ? 0.0 : clamp(0.24 + 0.13*log(1.0+perPx)/2.302585, 0.0, 0.88) * pow(cov, 0.55);
vec3 col = mix(bg, dust, v);
// THE LIGHT. Which repository owns the key at the centre of this pixel. This one is a tap, not
// a count: it says where a repository's work lies in time, and no number is read off it.
if (u_litRepo >= 0) { float kc = r*r; vec4 c = C(find(kc)); if (kc <= c.g && int(c.a + 0.5) == u_litRepo)
col = mix(col, vec3(0.13,0.93,0.47), u_points > 0.5 ? 0.10 : 0.72); }
// A PAGE IS A SCATTER, NOT A BAND. A repository is a contiguous span and a month is an annulus,
// but one file is neither: it was touched on nineteen separate days, so it lights nineteen separate
// runs of keys with other people's work between them. The flag rides in its own texture, one texel
// per commit, so the commit table that every other reading depends on is not touched to do it.
if (u_litPath == 1) { float kc = r*r; int i = find(kc); vec4 c = C(i);
if (kc <= c.g && texelFetch(u_pathf, ivec2(i % ${TW}, i / ${TW}), 0).r > 0.5)
col = mix(col, vec3(1.0,0.17,0.84), u_points > 0.5 ? 0.12 : 0.80); }
// A PERIOD IS A BAND. Keys run in time order, so a month or a day is one contiguous annulus.
if (u_litK.x >= 0.0 && r + h >= u_litK.x && r - h <= u_litK.y && cov > 0.0)
col = mix(col, vec3(0.13,0.93,0.47), u_points > 0.5 ? 0.10 : 0.72);
// THE PULSE travels outward from the centre, which on this wafer is forward through time. It is
// the instrument's sweep, not data, so it is faint over silence and bright over work.
if (u_pulse >= 0.0) { float d = abs(r - u_pulse) * u_zoom; col += vec3(0.45,0.95,1.0) * exp(-d*d/160.0) * (0.25 + 0.75*cov); }
// THE FLASH lights only keys issued at or after the boundary, and only where keys were issued.
if (u_flash > 0.0 && r + h >= u_newR && cov > 0.0) col = mix(col, vec3(1.0,0.69,0.0), u_flash);
o = vec4(col, 1.0);
}`;
const VS_KEYS = `#version 300 es
precision highp float;
uniform uint u_k0lo; uniform float u_R0, u_zoom, u_hot; uniform vec2 u_center, u_res;
out float v_hot;
void main(){
float d = float(gl_VertexID);
float r = u_R0 + (d + 0.5) / (u_R0 + sqrt(u_R0*u_R0 + d + 0.5) + 1e-9); // sqrt(k0+d+.5), kept precise
uint m = (u_k0lo + uint(gl_VertexID)) * ${G32}u;
float A = 6.283185307179586 * float(m >> 16) / 65536.0, B = 6.283185307179586 * float(m & 0xFFFFu) / 4294967296.0;
vec2 cs = vec2(cos(A)*cos(B) - sin(A)*sin(B), sin(A)*cos(B) + cos(A)*sin(B));
gl_Position = vec4((r*cs - u_center) * u_zoom / (0.5*u_res), 0.0, 1.0);
gl_PointSize = clamp(u_zoom * 0.34, 1.0, 9.0); v_hot = u_hot;
}`;
const FS_KEYS = `#version 300 es
precision highp float; in float v_hot; out vec4 o;
void main(){ if (length(gl_PointCoord-0.5) > 0.5) discard;
o = vec4(v_hot > 1.5 ? vec3(1.0,0.69,0.0) : (v_hot > 0.5 ? vec3(0.13,0.93,0.47) : vec3(0.79,0.83,0.90)), 1.0); }`;
function prog(vs, fs){ const p = gl.createProgram();
for (const [t,s] of [[gl.VERTEX_SHADER,vs],[gl.FRAGMENT_SHADER,fs]]) { const sh = gl.createShader(t);
gl.shaderSource(sh,s); gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(sh)); gl.attachShader(p,sh); }
gl.linkProgram(p); if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error(gl.getProgramInfoLog(p)); return p; }
const PF = prog(VS_FULL, FS_FIELD), PK = prog(VS_KEYS, FS_KEYS);
const U = (p, n) => gl.getUniformLocation(p, n);
gl.bindVertexArray(gl.createVertexArray());
let lost = false;
cv.addEventListener('webglcontextlost', e => { e.preventDefault(); lost = true;
hud.textContent = 'CONTEXT LOST. Nothing on screen is a count. Reload.'; });
// --------------------------------------------------------------------------------- the data
// cosmos/wafer.tsv: every commit in time order with its measured lines and the unissued keys
// before it. One file, about 400 kB, and then nothing else is ever fetched to draw the whole.
let N = 0, SPACE = 0, repos = [], commits = [];
async function tsv(url){ const r = await fetch(url); if (!r.ok) throw new Error(url);
return (await r.text()).split('\n').filter(l => l && l[0] !== '#').map(l => l.split('\t')); }
Promise.all([tsv('cosmos/repos.tsv'), tsv('cosmos/wafer.tsv'),
tsv('cosmos/cards/list.tsv').catch(() => []),
tsv('cosmos/public.tsv').catch(() => [])]).then(([rr, ww, cc, pp]) => {
// WHO OWNS EACH PIECE OF WORK, AND WHETHER ANYBODY MAY SEE IT. A link is only honest for a
// repository GitHub says is public: for anything else the address itself would put a private name
// in front of a reader, and the link would be a dead end for everyone but its owner.
const owners = new Map(pp.map(p => [p[0], { owner:p[1], pub:p[2] === 'yes' }]));
cards = cc.map(p => ({ path:p[0], repo:p[1], k0:+p[2], lines:+p[3], file:p[4], commit:p[5],
here:p[6] === 'yes', owner:p[7], unix:+p[8] }));
repos = rr.map(p => { const o = owners.get(p[1]) || { owner:'', pub:false };
return { i:+p[0], name:p[1], lines:+p[2], seen:0, commits:0, owner:o.owner, pub:o.pub }; });
let k = 0, issued = 0;
commits = ww.map(p => { k += +p[4]; const c = { unix:+p[0], lines:+p[1], repo:+p[2], sha:p[3], gap:+p[4], k0:k, cum:issued };
k += c.lines; issued += c.lines; c.k1 = k; repos[c.repo].seen += c.lines; repos[c.repo].commits++;
if (!repos[c.repo].t0) repos[c.repo].t0 = c.unix; repos[c.repo].t1 = c.unix; // commits are in time order
return c; });
const bad = repos.find(r => r.seen !== r.lines);
if (bad) { hud.textContent = 'REFUSED: the commits of ' + bad.name + ' sum to ' + fmt(bad.seen) + ', the belt says ' + fmt(bad.lines); return; }
N = issued; SPACE = k;
const H = Math.ceil(commits.length / TW), a = new Float32Array(TW * H * 4);
commits.forEach((c, i) => { a[i*4] = c.k0; a[i*4+1] = c.k1; a[i*4+2] = c.cum; a[i*4+3] = c.repo; });
gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, gl.createTexture());
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, TW, H, 0, gl.RGBA, gl.FLOAT, a);
pathFlags = new Float32Array(TW * H); pathTex = gl.createTexture();
gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, pathTex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, TW, H, 0, gl.RED, gl.FLOAT, pathFlags);
pathRows = H; commits.forEach((c, i) => bySha.set(c.sha, i)); gl.activeTexture(gl.TEXTURE0);
big.textContent = 'Engineering record';
sub.textContent = fmt(commits.length) + ' pieces of work across ' + repos.length + ' areas, '
+ new Date(commits[0].unix*1000).toISOString().slice(0,10) + ' to '
+ new Date(commits[commits.length-1].unix*1000).toISOString().slice(0,10)
+ ' · oldest in the middle, newest at the edge';
home(); dirty = true;
{ const st = new URLSearchParams(location.search).get('selftest') || '', mt = st.match(/^(20\d\d)-(\d\d)$/);
if (mt) setTimeout(() => { tween = null; const R = Math.sqrt(SPACE); cx = 0; cy = 0; zoom = (Math.min(cv.width, cv.height)/2)*0.80/R;
const got = lightTime(+mt[1], +mt[2], 0); tween = null; cx = 0; cy = 0; zoom = (Math.min(cv.width, cv.height)/2)*0.80/R; draw();
let direct = 0; if (got) for (let i = got.i0; i < got.i1; i++) direct += commits[i].lines;
// A lit period contains its own nights, so one pixel proves nothing: the first version of this
// test sampled the middle of July, landed on a silent ring and failed correctly for the wrong
// reason. Scan right across the band. Work must be green, silence must be dark, nothing else.
const px = new Uint8Array(4); let green = 0, dark = 0, other = 0; const seen = [];
const xa = Math.round(cv.width/2 + litK[0]*zoom), xb = Math.round(cv.width/2 + litK[1]*zoom);
for (let x = xa; x <= xb; x++) { gl.readPixels(x, Math.round(cv.height/2), 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px);
const g = px[1] > 120 && px[1] > px[0] + 40 && px[1] > px[2] + 30, d = px[0] < 60 && px[1] < 60 && px[2] < 70;
if (g) green++; else if (d) dark++; else other++; if (seen.length < 12) seen.push([px[0], px[1], px[2]]); }
const T = { period: st, commits: got ? got.i1 - got.i0 : 0, lines_by_running_total: got ? got.lines : 0, lines_added_directly: direct,
T1_running_total_equals_direct_sum: !!got && got.lines === direct,
T2_work_is_green_and_silence_is_dark: green > 0 && other === 0, pixels_across_band: { green, dark, other }, first_pixels: seen };
T.PASS = T.T1_running_total_equals_direct_sum && T.T2_work_is_green_and_silence_is_dark; window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL'); }, 400); }
if (new URLSearchParams(location.search).get('selftest') === 'new') { selftest = {}; tween = null; setTimeout(() => showNew(24), 300); }
if (new URLSearchParams(location.search).get('selftest') === 'phone') setTimeout(phoneSelftest, 500);
{ const mr = (new URLSearchParams(location.search).get('selftest') || '').match(/^repo:(.+)$/);
if (mr) setTimeout(() => repoSelftest(decodeURIComponent(mr[1])), 500); }
{ const mc = (new URLSearchParams(location.search).get('selftest') || '') === 'card';
if (mc) setTimeout(() => cardSelftest(), 600); }
{ const mp = (new URLSearchParams(location.search).get('selftest') || '').match(/^path:(.+)$/);
// A TEST THAT CANNOT RUN MUST FAIL, NOT GO QUIET. The first run of this one fetched a file the
// iteration folder did not have, the promise was rejected with nobody listening, and the page
// kept its ordinary title and scored nothing while looking like nothing had happened.
if (mp) setTimeout(() => pathSelftest(decodeURIComponent(mp[1])).catch(e => {
window.__selftest = { PASS:false, asked_for:mp[1], error:String(e && e.message || e) };
document.title = 'selftest FAIL'; }), 500); }
{ const dk = new URLSearchParams(location.search).get('key'); // the deep link: ?key=<key>
if (dk && /^[0-9]+$/.test(dk)) setTimeout(() => goKey(+dk), 400); }
{ const dp = new URLSearchParams(location.search).get('path'); // the deep link: ?path=<prefix>
if (dp) setTimeout(() => lightPath(decodeURIComponent(dp)), 400); }
}).catch(() => { hud.textContent = 'cosmos/wafer.tsv did not load. The wafer will not invent its keys.'; });
// ------------------------------------------------------------------------ camera and address
let cx = 0, cy = 0, zoom = 1, dirty = true, tween = null, litRepo = -1, target = null;
let pulse = -1, flash = 0, newFrom = -1, anim = null, selftest = null, litK = [-1,-1], litCi = null;
let detail = false; // d shows the engineering readout; a reader never sees it
let litPath = null, pathTex = null, pathFlags = null, pathRows = 0, tracked = null; const bySha = new Map();
let cards = [], cardCache = {}, cardShown = null;
let atHome = true; // true while the camera has not been moved by hand
const elHudTop = hud, elTop = document.getElementById('top'), elFoot = document.getElementById('foot');
const narrow = () => innerWidth <= 640; // one number, used by the layout and by the test
function resize(){ cv.width = ov.width = innerWidth; cv.height = ov.height = innerHeight; gl.viewport(0,0,cv.width,cv.height);
if (typeof layout === 'function') layout();
if (atHome && SPACE) { const h = homeCamera(); cx = h.x; cy = h.y; zoom = h.z; tween = null; } // turning the phone re-fits, moving by hand does not
dirty = true; }
addEventListener('resize', resize); resize();
function flyTo(x, y, z){ tween = { t0:performance.now(), x0:cx, y0:cy, z0:zoom, x1:x, y1:y, z1:z, dur:900 }; }
// THE SAFE RECTANGLE. The panels are position:fixed, so the wafer cannot be centred on the window
// and be clear of them at the same time. layout() measures the panels as they really are after
// every change of text or size, and safeBox() returns what is left. Nothing here is assumed: the
// numbers come from getBoundingClientRect, which is what the browser actually laid out.
function layout(){
elHudTop.style.top = narrow() ? elTop.offsetHeight + 'px' : '0px'; // on a phone the HUD sits under the header, not beside it
card.style.bottom = (elFoot.offsetHeight + 10) + 'px'; // the card never hides the commands
}
function safeBox(){
layout();
let top = 0, bot = innerHeight;
for (const el of [elTop, elHudTop]) { const r = el.getBoundingClientRect(); if (r.width > 0 && r.height > 0) top = Math.max(top, r.bottom); }
const f = elFoot.getBoundingClientRect(); if (f.height > 0) bot = Math.min(bot, f.top);
return { x0:8, x1:innerWidth - 8, y0:top + 8, y1:Math.max(top + 24, bot - 8) };
}
// home() puts the whole wafer inside that rectangle, not inside the window: the circle is as big
// as the clear space allows and its centre is the centre of the clear space, which on a phone is
// above the middle of the screen.
function homeCamera(){
const s = safeBox(), R = Math.min(s.x1 - s.x0, s.y1 - s.y0) / 2 * 0.80;
const z = R / Math.sqrt(SPACE), mx = (s.x0 + s.x1)/2, my = (s.y0 + s.y1)/2;
return { z, x:(innerWidth/2 - mx)/z, y:(my - innerHeight/2)/z };
}
function home(){ const h = homeCamera(); atHome = true; flyTo(h.x, h.y, h.z); }
function keyPlace(k){ const m = Math.imul((k % 4294967296) >>> 0, G32) >>> 0, th = 2*Math.PI*m/4294967296, r = Math.sqrt(k + 0.5);
return [r*Math.cos(th), r*Math.sin(th)]; }
function findBy(field, v){ let lo = 0, hi = commits.length - 1; while (lo < hi) { const m = (lo+hi+1)>>1; if (commits[m][field] <= v) lo = m; else hi = m-1; } return lo; }
// an address key resolves to a commit by binary search; no walking, and silence is an answer too
function address(k){ if (!(k >= 0) || k >= SPACE) return null; const i = findBy('k0', k), c = commits[i];
return (k >= c.k0 && k < c.k1) ? { k, i, c, m:k - c.k0 } : { k, i, c, silent:true, next:commits[i + (k < c.k0 ? 0 : 1)] }; }
// WHAT A DOT SAYS WHEN ITS CODE IS NOT CARRIED HERE. Three plain things: what the work was, the day
// it was done, and one link to it. This used to answer with address arithmetic and an instruction to
// run a command on a computer the reader has not got, which is almost every tap a stranger makes.
function describe(a){
if (!a) return '';
if (a.silent) { const x = a.next;
return 'Nothing was recorded here.'
+ (x ? '\nThe next work was <b>' + repos[x.repo].name + '</b>, ' + day(x.unix) + '.' : ''); }
const r = repos[a.c.repo];
const u = r.pub ? gh({ owner:r.owner, repo:r.name, commit:a.c.sha }) : null;
return '<b>' + r.name + '</b> \u00b7 work of ' + day(a.c.unix)
+ '\n' + (u ? '<a href="' + u + '" target="_blank" rel="noopener">Open this piece of work on GitHub</a>'
: 'This work is not public.')
+ '\nThe code for this line is not carried here yet.';
}
// THE SAME ARITHMETIC THE SHADER USES, written out in the page so it can be checked against it.
// issuedBelow(k) is how many keys were issued below address k: a running total to the start of the
// commit that owns k, plus however far into that commit k lies. The fragment shader computes this
// exact expression for every pixel to decide its shade, so if these two ever disagree the picture
// is wrong, and proof 7 is the check that they do not.
function issuedBelow(k){ const c = commits[findBy('k0', k)]; return c.cum + Math.min(Math.max(k - c.k0, 0), c.k1 - c.k0); }
// which repository owns the key at radius r: -1 is silence, -2 is off the wafer
function ownerAt(r){ const kc = r*r; if (!(kc < SPACE)) return -2; const c = commits[findBy('k0', kc)];
return (kc >= c.k0 && kc <= c.k1) ? c.repo : -1; }
// a repository's lines counted through the running totals alone, never by adding its commits up
// HOW WIDE A REPOSITORY IS ON THE SCREEN. A key at radius r sits in a ring of 2 r dr addresses,
// so one pixel holds 2 r / zoom addresses and a commit of L lines is L zoom / 2 r pixels wide.
// Under one pixel, not one pixel centre can fall inside it and the light is invisible. That is a
// fact about the wafer, not a fault in the drawing, and the page says it rather than hiding it.
function widestRunPx(ri, z){
const span = (k0, k1) => (k1 - k0) * z / (2 * Math.sqrt((k0 + k1)/2));
let w = 0, a = -1, b = -1;
for (const c of commits) {
if (c.repo === ri && a >= 0 && c.k0 === b) { b = c.k1; } // no silence between them: one unbroken run
else if (c.repo === ri) { if (a >= 0) w = Math.max(w, span(a, b)); a = c.k0; b = c.k1; }
else if (a >= 0) { w = Math.max(w, span(a, b)); a = -1; }
}
return a >= 0 ? Math.max(w, span(a, b)) : w; }
function linesByRunningTotals(ri){ let t = 0; for (const c of commits) if (c.repo === ri) t += issuedBelow(c.k1) - issuedBelow(c.k0); return t; }
function keyAt(wx, wy){ const r = Math.hypot(wx, wy), kc = Math.round(r*r), span = Math.ceil(6*r + 8); let best = -1, bd = 0.6;
for (let k = Math.max(0, kc - span); k <= Math.min(SPACE-1, kc + span); k++) { const p = keyPlace(k), d = Math.hypot(p[0]-wx, p[1]-wy); if (d < bd) { bd = d; best = k; } }
return best; }
// --------------------------------------------------------------------------------- the frame
const POINTS_FROM = 1.0, MAX_CALLS = 3000;
function frame(){
if (lost) return;
if (tween) { const u = Math.min(1, (performance.now()-tween.t0)/tween.dur), e = u<0.5 ? 2*u*u : 1-Math.pow(-2*u+2,2)/2;
zoom = Math.exp(Math.log(tween.z0) + (Math.log(tween.z1)-Math.log(tween.z0))*e);
cx = tween.x0 + (tween.x1-tween.x0)*e; cy = tween.y0 + (tween.y1-tween.y0)*e; dirty = true; if (u >= 1) tween = null; }
if (anim) stepAnim();
if (dirty && N) { draw(); dirty = false; }
requestAnimationFrame(frame);
}
function draw(){
const R = Math.sqrt(SPACE), W = cv.width, H = cv.height;
const x0 = cx - W/2/zoom, x1 = cx + W/2/zoom, y0 = cy - H/2/zoom, y1 = cy + H/2/zoom;
const dx = x0 > 0 ? x0 : (x1 < 0 ? -x1 : 0), dy = y0 > 0 ? y0 : (y1 < 0 ? -y1 : 0);
const rmin = Math.hypot(dx, dy), rmax = Math.max(Math.hypot(x0,y0), Math.hypot(x1,y0), Math.hypot(x0,y1), Math.hypot(x1,y1));
const ka = Math.min(SPACE, Math.floor(rmin*rmin)), kb = Math.min(SPACE, Math.ceil(rmax*rmax));
// the screen's radii are a contiguous run of addresses; the issued ones among them are whole commits and two part commits
let i0 = findBy('k0', ka), segs = [], total = 0;
if (zoom >= POINTS_FROM) for (let i = i0; i < commits.length && commits[i].k0 < kb && segs.length <= MAX_CALLS; i++) {
const s0 = Math.max(commits[i].k0, ka), s1 = Math.min(commits[i].k1, kb); if (s1 > s0) { segs.push([s0, s1, commits[i].repo, i]); total += s1 - s0; } }
const points = zoom >= POINTS_FROM && segs.length <= MAX_CALLS && total < 1.6e9;
gl.useProgram(PF);
gl.uniform2f(U(PF,'u_res'), W, H); gl.uniform2f(U(PF,'u_center'), cx, cy); gl.uniform1f(U(PF,'u_zoom'), zoom);
gl.uniform1f(U(PF,'u_R'), R); gl.uniform1f(U(PF,'u_points'), points ? 1 : 0);
gl.uniform2f(U(PF,'u_litK'), litK[0], litK[1]);
gl.uniform1f(U(PF,'u_pulse'), pulse); gl.uniform1f(U(PF,'u_flash'), flash);
gl.uniform1f(U(PF,'u_newR'), newFrom >= 0 ? Math.sqrt(commits[newFrom].k0) : 1e30);
gl.uniform1i(U(PF,'u_commits'), 0); gl.uniform1i(U(PF,'u_n'), commits.length); gl.uniform1i(U(PF,'u_litRepo'), litRepo);
gl.uniform1i(U(PF,'u_pathf'), 1); gl.uniform1i(U(PF,'u_litPath'), litPath ? 1 : 0);
gl.drawArrays(gl.TRIANGLES, 0, 3);
if (selftest && selftest.wantPixels && flash > 0.5 && !points) {
const px = new Uint8Array(4), R0 = Math.sqrt(commits[newFrom].k0), rm = (R0 + R) / 2;
const read = (wx) => { gl.readPixels(Math.round(W/2 + (wx - cx)*zoom), Math.round(H/2 + (0 - cy)*zoom), 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px); return [px[0], px[1], px[2]]; };
selftest.newBandPixel = read(rm); selftest.pupilPixel = read(0); selftest.wantPixels = false; }
let ms = 0;
if (points) { const t0 = performance.now(); gl.useProgram(PK);
gl.uniform1f(U(PK,'u_zoom'), zoom); gl.uniform2f(U(PK,'u_center'), cx, cy); gl.uniform2f(U(PK,'u_res'), W, H);
for (const [s0, s1, rp, ci] of segs) { gl.uniform1f(U(PK,'u_hot'), (newFrom >= 0 && ci >= newFrom) ? 2 : ((rp === litRepo || (litCi && ci >= litCi[0] && ci < litCi[1])) ? 1 : 0));
for (let off = s0; off < s1; off += 4000000) { // bounded calls; the driver watchdog is real
gl.uniform1ui(U(PK,'u_k0lo'), (off % 4294967296) >>> 0); gl.uniform1f(U(PK,'u_R0'), Math.sqrt(off));
gl.drawArrays(gl.POINTS, 0, Math.min(4000000, s1 - off)); } }
gl.finish(); ms = performance.now() - t0; }
const L = [], D = [];
D.push(points ? 'RESOLVED · every issued key whose radius is in the field, drawn at its own place'
: 'UNRESOLVED · up to ' + words(1/(Math.PI*zoom*zoom)) + ' keys to a pixel · each pixel’s issued count is computed from the law, not drawn');
if (points) D.push(fmt(total) + ' issued keys from ' + fmt(segs.length) + ' commits passed to the GPU in ' + ms.toFixed(0) + ' ms');
D.push('the whole · ' + fmt(N) + ' issued + ' + fmt(SPACE - N) + ' silent = ' + fmt(SPACE) + ' addresses');
if (litRepo >= 0) { const rt = linesByRunningTotals(litRepo), rr = repos[litRepo];
// the number on screen is the one the shading is made of, not the one the belt declared; if
// they differ the HUD says so rather than picking the prettier of the two
// WHAT IS HIGHLIGHTED, IN WORDS A READER CAME WITH. Whether two running totals agree is how
// this page knows it is not lying, which matters, and belongs where the rest of the working
// is: behind d. What stays on the face is the disagreement itself, if there ever is one,
// because a reader must never be shown a number the page has reason to doubt.
L.push('HIGHLIGHTED · ' + rr.name + ' · ' + fmt(rr.commits) + ' pieces of work · '
+ day(rr.t0) + ' to ' + day(rr.t1));
D.push('running totals ' + (rt === rr.lines ? 'agree with the belt' : 'DISAGREE with the belt'));
if (rt !== rr.lines) L.push('THIS COUNT IS IN DOUBT · two measurements of it disagree, so it is not shown');
const wpx = widestRunPx(litRepo, zoom);
// Said exactly, because 269 pixels of a repository whose widest run is a tenth of a pixel are
// lit: the runs are so close together that pixel centres keep landing inside them. The claim
// is about the run, not about the light.
if (wpx < 1) L.push('TOO SMALL TO SEE AT THIS ZOOM · what is lit is only where this work happens to fall · zoom in to see it whole'); }
D.push(zoom >= 1 ? 'zoom ' + zoom.toFixed(1) + ' px per key spacing' : 'zoom 1 px = ' + words(1/zoom) + ' units');
hud.textContent = (detail ? L.concat(D) : L).join('\n');
o2.clearRect(0,0,ov.width,ov.height);
{ const x0 = (0 - cx)*zoom + ov.width/2, y0 = ov.height/2 + cy*zoom, M = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
const a = new Date(commits[0].unix*1000), b = new Date(commits[commits.length-1].unix*1000); let lastPx = -99;
o2.font = '10px ui-monospace,Consolas,monospace'; o2.lineWidth = 1;
for (let y = a.getUTCFullYear(), m = a.getUTCMonth() + 1; y < b.getUTCFullYear() || (y === b.getUTCFullYear() && m <= b.getUTCMonth()); m++) {
if (m > 11) { m = 0; y++; }
const t = Date.UTC(y, m, 1)/1000, i = Math.min(commits.length-1, findBy('unix', t - 1) + 1), rp = Math.sqrt(commits[i].k0)*zoom;
if (rp - lastPx < 26 || rp > 6000) continue; lastPx = rp;
o2.strokeStyle = 'rgba(46,230,230,.30)'; o2.beginPath(); o2.arc(x0, y0, rp, 0, 6.2832); o2.stroke();
o2.fillStyle = 'rgba(46,230,230,.85)'; o2.fillText(M[m] + ' ' + String(y).slice(2), x0 + rp*0.5 + 4, y0 - rp*0.866 - 3); } }
if (target && target.boundary && zoom >= POINTS_FROM) {
// at this zoom the boundary circle is straight across the screen: perpendicular to the radius
const x = (target.x - cx)*zoom + ov.width/2, y = ov.height/2 - (target.y - cy)*zoom, rr = Math.hypot(target.x, target.y) || 1;
const tx = -target.y/rr, ty = target.x/rr, Lp = Math.hypot(ov.width, ov.height);
o2.strokeStyle = 'rgba(255,199,107,.95)'; o2.lineWidth = 2; o2.setLineDash([10,6]); o2.beginPath();
o2.moveTo(x - tx*Lp, y + ty*Lp); o2.lineTo(x + tx*Lp, y - ty*Lp); o2.stroke(); o2.setLineDash([]);
o2.font = '12px ui-monospace,Consolas,monospace'; o2.fillStyle = 'rgba(255,199,107,1)';
// outward is newer, and which way outward points on screen depends on where this key sits, so
// the words are placed along the real radius rather than assumed to read left to right
const ox = target.x/rr, oy = -target.y/rr;
o2.textAlign = 'center';
o2.fillText('NEW CODE', x + ox*110, y + oy*110); o2.fillStyle = 'rgba(213,220,234,.85)';
o2.fillText('older', x - ox*110, y - oy*110); o2.fillStyle = 'rgba(255,199,107,1)';
o2.fillText('the boundary', x + tx*150, y - ty*150 - 8); o2.textAlign = 'start'; }
if (target) { const x = (target.x - cx)*zoom + ov.width/2, y = ov.height/2 - (target.y - cy)*zoom;
o2.strokeStyle = 'rgba(255,43,214,.98)'; o2.lineWidth = 1.5; o2.beginPath();
for (const [a,b,c,d] of [[-16,0,-6,0],[6,0,16,0],[0,-16,0,-6],[0,6,0,16]]) { o2.moveTo(x+a,y+b); o2.lineTo(x+c,y+d); } o2.stroke(); }
}
// ------------------------------------------------------------------------------ the controls
function toWorld(px, py){ return [cx + (px - innerWidth/2)/zoom, cy - (py - innerHeight/2)/zoom]; }
// A KEY THAT LANDS IN A CARRIED FILE SHOWS THE CODE. Until every commit's file list is published a
// browser cannot work out which file a key belongs to, so the answer is worked out beforehand, one
// public file at a time, and the page simply looks it up. Where there is no card the page says what
// it knows and does not pretend otherwise.
function cardFor(k){ return cards.find(c => k >= c.k0 && k < c.k0 + c.lines) || null; }
function esc(t){ return String(t).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); }
const CONTEXT = 10;
// THE ONE RULE THAT MAKES THE ADDRESS OF A LINE ON GITHUB, the same rule tools/cards.py writes
// down, so a change of commit ids can be answered by making every link again from the fields.
// The owner used to be written in here by hand: correct by luck, and wrong the first time a
// carried file came from anywhere else.
// ONE RULE, TWO SHAPES. A whole piece of work is a commit; a line is a path inside it. Nothing in
// this page types a GitHub address: every one of them comes out of here, from data, so when the
// commit ids change they can all be made again by rebuilding the data.
function gh(o){
if (!o || !o.owner || !o.repo || !o.commit) return null;
const base = 'https://github.com/' + o.owner + '/' + o.repo;
if (!o.path) return base + '/commit/' + o.commit;
return base + '/blob/' + o.commit + '/' + o.path + (o.line ? '#L' + o.line : '');
}
function ghLink(c, line){
return gh({ owner:c.owner, repo:c.repo, commit:c.commit, path:c.path, line:line });
}
function renderCode(c, j, data){
const when = day(data.commit_unix || c.unix);
const head = '<div class="ch"><b>' + esc(c.repo) + '</b> \u00b7 ' + esc(c.path)
+ ' \u00b7 line ' + fmt(j + 1) + ' \u00b7 ' + when + '</div>';
// A FILE THAT IS GONE GETS ONE SENTENCE AND A LINK, AND NO LINES. Showing what a removed file used
// to say, as though it were still there, would be the page telling a reader something untrue.
if (!c.here) return head + '<div class="cb">This file was later removed.</div>'
+ '<div class="cf"><a href="' + ghLink(c) + '" target="_blank" rel="noopener">Open it on GitHub at that commit</a></div>';
const a = Math.max(0, j - CONTEXT), b = Math.min(data.text.length - 1, j + CONTEXT), rows = [];
for (let i = a; i <= b; i++)
rows.push('<span class="cl' + (i === j ? ' hit' : '') + '" data-line="' + (i + 1) + '">'
+ '<span class="ln">' + (i + 1) + '</span><span class="tx">' + esc(data.text[i]) + '</span></span>');
return head + '<div class="cb">' + rows.join('') + '</div>'
+ '<div class="cf"><a href="' + ghLink(c, j + 1) + '" target="_blank" rel="noopener">Open line '
+ fmt(j + 1) + ' on GitHub at that commit</a></div>';
}
function show(a){
card.style.display = 'block'; card.classList.remove('sheet'), card.innerHTML = describe(a); if (a && !a.silent) litRepo = a.c.repo; dirty = true;
const c = a && !a.silent ? cardFor(a.k) : null;
cardShown = null;
if (!c) return;
const j = a.k - c.k0, put = data => {
cardShown = { card:c, line:j, data };
card.innerHTML = renderCode(c, j, data); card.classList.add('sheet');
// AND THE PANEL MUST BE TOLD IT IS A SHEET. It is shown by setting display on the element
// itself, and an inline style beats a style sheet: the three parts were stacked as plain
// blocks, the code ran past the foot of the panel and the link went under the button bar
// while every measurement said it was on the screen.
card.style.display = 'flex'; dirty = true;
// A THIRD OF THE WAY DOWN, NOT AT THE TOP. The tapped line is the answer; the lines under it are
// what the answer is part of, and a reader should not have to scroll to learn that there are any.
const bdy = card.querySelector('.cb'), hit = bdy && bdy.querySelector('.cl.hit');
if (bdy && hit) {
// WHERE A LINE IS, IN THE ONLY COORDINATES THAT NEED NO CORRECTING. offsetTop is measured from
// the nearest positioned ancestor, which is the panel and not the scrolling box inside it; two
// corrections for that difference each left half a line of code above the first number.
const rows = Array.prototype.slice.call(bdy.querySelectorAll('.cl'));
const yOf = el => el.getBoundingClientRect().top - bdy.getBoundingClientRect().top + bdy.scrollTop;
bdy.scrollTop = Math.max(0, yOf(hit) - bdy.clientHeight * 0.34);
// AND IT STOPS AT THE TOP OF A LINE. A line cut in half at the top of the sheet reads as a line
// the page is hiding, rather than one it has scrolled past.
const now = bdy.scrollTop; let snap = 0;
for (const r of rows) { const y = yOf(r); if (y <= now + 0.5) snap = y; }
bdy.scrollTop = Math.max(0, snap);
}
};
if (cardCache[c.file]) { put(cardCache[c.file]); return; }
card.classList.remove('sheet'), card.innerHTML = describe(a) + '\n\nreading the file...';
fetch('cosmos/cards/' + c.file).then(r => r.json()).then(d => { cardCache[c.file] = d; put(d); })
.catch(() => { card.classList.remove('sheet'), card.innerHTML = describe(a) + '\n\nthe file for this line could not be read'; });
}
function goKey(k){ const p = keyPlace(k); target = { x:p[0], y:p[1] }; show(address(k)); flyTo(p[0], p[1], 14); }
// SHOW NEW CODE. "New" is measured from the newest commit, not from the wall clock, so the same
// page gives the same answer tomorrow. Keys run in time order, so what is new is always one
// contiguous band at the rim: the boundary is a single circle, and that circle is drawn.
function showNew(hours){
const last = commits[commits.length-1].unix, cut = last - hours*3600;
newFrom = findBy('unix', cut - 1) + (commits[0].unix >= cut ? 0 : 1); if (newFrom >= commits.length) newFrom = commits.length - 1;
litRepo = -1; target = null; card.style.display = 'none'; tween = null;
const R = Math.sqrt(SPACE); cx = 0; cy = 0; zoom = (Math.min(cv.width, cv.height)/2) * 0.80 / R;
anim_hours = hours; anim = { t0:performance.now(), hours, R }; dirty = true;
}
function stepAnim(){
const t = (performance.now() - anim.t0) / 1000; dirty = true;
if (t < 1.6) { const u = t/1.6; pulse = anim.R * (u*u*(3-2*u)); flash = 0; }
else if (t < 2.5) { pulse = -1; flash = 1 - 0.45*((t-1.6)/0.9); if (selftest && selftest.wantPixels === undefined) selftest.wantPixels = true; }
else { const c = commits[newFrom], n = commits.length - newFrom; let lines = 0; for (let i = newFrom; i < commits.length; i++) lines += commits[i].lines;
flash = 0.35; anim = null; const p = keyPlace(c.k0); target = { x:p[0], y:p[1], boundary:true };
card.style.display = 'block';
{ const r0 = repos[c.repo], u0 = r0.pub ? gh({ owner:r0.owner, repo:r0.name, commit:c.sha }) : null;
card.classList.remove('sheet');
card.innerHTML = 'NEW CODE · the last ' + anim_hours + ' hours of work, as a band at the rim'
+ '\n<b>' + fmt(n) + '</b> pieces of work, <b>' + fmt(lines) + '</b> lines added'
+ '\nbegins with <b>' + r0.name + '</b>, ' + day(c.unix)
+ (u0 ? '\n<a href="' + u0 + '" target="_blank" rel="noopener">Open this piece of work on GitHub</a>' : ''); }
flyTo(p[0], p[1], 14);
if (selftest) finishSelftest(c, n, lines); }
}
let anim_hours = 24;
// THE TESTS, run by the page on itself with ?selftest=new, so the verdict is not an opinion.
function finishSelftest(c, n, lines){
let maxOld = 0; for (let i = 0; i < newFrom; i++) maxOld = Math.max(maxOld, commits[i].k1);
const a = address(c.k0), nb = selftest.newBandPixel || [0,0,0], pp = selftest.pupilPixel || [0,0,0];
const T = { T1_new_is_one_band_beyond_everything_older: c.k0 >= maxOld,
T2_boundary_key_resolves_to_a_new_commit: !!(a && !a.silent && a.i >= newFrom && a.m === 0),
T3_flash_is_amber_on_the_new_band: nb[0] > 150 && nb[0] > nb[2] + 40,
T3_no_flash_on_the_silent_centre: pp[0] < 40 && pp[1] < 40,
new_commits: n, new_lines: lines, boundary_key: c.k0, newBandPixel: nb, pupilPixel: pp };
T.PASS = T.T1_new_is_one_band_beyond_everything_older && T.T2_boundary_key_resolves_to_a_new_commit && T.T3_flash_is_amber_on_the_new_band && T.T3_no_flash_on_the_silent_centre;
window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}
// ------------------------------------------------------------------ where a page is on the wafer
// A PAGE IS NOT A PLACE. tools/where.py asks git which commits touched a path and cosmos/wafer.tsv
// where each of those commits landed, and writes both files this reads. The page then does the same
// key arithmetic over its own commit table and the test is that the two agree exactly, commit by
// commit, key by key. Neither is trusted: they are made to contradict each other or agree.
async function loadTracked(){
if (tracked) return tracked;
const [tt, cc] = await Promise.all([tsv('cosmos/tracked.tsv'), tsv('cosmos/tracked-commits.tsv')]);
tracked = { paths:tt.map(p => ({ repo:p[0], path:p[1], use:p[2], in_git:+p[3], on_wafer:+p[4],
lines_in_those_commits:+p[5], k0:+p[6], k1:+p[7], first:p[8], last:p[9] })),
commits:cc.map(p => ({ path:p[0], sha:p[1], unix:+p[2], lines:+p[3], k0:+p[4], k1:+p[5] })) };
return tracked;
}
function raiseFlags(idx){
pathFlags.fill(0); for (const i of idx) pathFlags[i] = 1;
gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, pathTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, TW, pathRows, 0, gl.RED, gl.FLOAT, pathFlags);
gl.activeTexture(gl.TEXTURE0);
}
async function lightPath(name, quiet){
const T = await loadTracked();
const row = T.paths.find(p => p.path.toLowerCase() === String(name).toLowerCase());
if (!row) return { error:'no tracked page of that name: run tools/where.py --five', asked_for:name };
const want = T.commits.filter(c => c.path === row.path);
const idx = [], missing = [], disagreed = [];
for (const c of want) { const i = bySha.get(c.sha);
if (i === undefined) { missing.push(c.sha); continue; }
if (commits[i].k0 !== c.k0 || commits[i].k1 !== c.k1) disagreed.push({ sha:c.sha, page:[commits[i].k0, commits[i].k1], tool:[c.k0, c.k1] });
idx.push(i); }
idx.sort((a, b) => a - b);
litRepo = -1; litK = [-1,-1]; litCi = null; newFrom = -1; flash = 0; pulse = -1; target = null;
litPath = { row, idx }; raiseFlags(idx);
tween = null; cx = 0; cy = 0; zoom = (Math.min(cv.width, cv.height)/2)*0.80/Math.sqrt(SPACE); draw();
if (!quiet) { card.style.display = 'block';
card.classList.remove('sheet'), card.innerHTML = 'PATH:' + row.path + '\n' + row.repo + '\n\n' + fmt(row.on_wafer) + ' commits touched it, of ' + fmt(row.in_git)
+ ' git knows\nfirst ' + row.first + ', last ' + row.last
+ '\n\nkeys ' + fmt(row.k0) + ' .. ' + fmt(row.k1)
+ '\n' + fmt(row.lines_in_those_commits) + ' lines in those commits, which is the commits, not the page'
+ '\n\nuse: ' + row.use; }
return { row, idx, want:want.length, missing, disagreed };
}
// THE TEST. ?selftest=path:<name>. The count the page lit must be the count the tool counted, every
// sha the tool named must be a commit this wafer holds, and every key must match to the digit. Then
// the picture: at a zoom where one of those commits is more than a pixel wide, that pixel must
// actually carry the path's light, or the page is lighting a set it never drew.
async function pathSelftest(name){
const r = await lightPath(name, true);
if (r.error) { window.__selftest = { PASS:false, asked_for:name, error:r.error }; document.title = 'selftest FAIL'; return; }
let raised = 0; for (let i = 0; i < pathFlags.length; i++) if (pathFlags[i] > 0.5) raised++;
const T = { page:r.row.path, repository:r.row.repo, use:r.row.use,
commits_lit_by_the_page:r.idx.length, commits_counted_by_where_py:r.row.on_wafer, commits_git_knows:r.row.in_git,
shas_the_wafer_does_not_hold:r.missing, keys_where_tool_and_page_disagree:r.disagreed, flags_raised_in_the_texture:raised,
first_key:r.row.k0, last_key:r.row.k1,
T1_the_page_lit_what_where_py_counted: r.idx.length === r.row.on_wafer && r.idx.length === r.want,
T2_every_sha_the_tool_named_is_on_this_wafer: r.missing.length === 0,
T3_tool_and_page_give_every_commit_the_same_keys: r.disagreed.length === 0,
T4_the_light_was_actually_raised: raised === r.idx.length && r.idx.length > 0 };
// the picture: the widest of its commits, at a zoom that makes it three pixels of radius
let best = -1, bestW = 0;
for (const i of r.idx) { const w = Math.sqrt(commits[i].k1) - Math.sqrt(commits[i].k0); if (w > bestW) { bestW = w; best = i; } }
const zWant = 3/Math.max(bestW, 1e-12), z = Math.min(zWant, POINTS_FROM*0.9), wpx = bestW*z;
T.widest_commit_px_at_the_zoom_used = +wpx.toFixed(3);
if (best >= 0 && wpx >= 1) {
const mid = (Math.sqrt(commits[best].k0) + Math.sqrt(commits[best].k1))/2, p = keyPlace(mid*mid);
tween = null; cx = p[0]; cy = p[1]; zoom = z; dirty = true; draw();
const px = new Uint8Array(4); gl.readPixels(Math.round(cv.width/2), Math.round(cv.height/2), 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px);
T.pixel_at_the_middle_of_its_widest_commit = [px[0], px[1], px[2]];
T.T5_that_pixel_carries_the_paths_light = px[0] > 120 && px[2] > 100 && px[0] > px[1] + 40 && px[2] > px[1] + 30;
} else { T.T5_that_pixel_carries_the_paths_light = null; T.why_no_pixel_was_read = 'every commit of this page is finer than one pixel at any zoom the field is drawn at'; }
T.PASS = T.T1_the_page_lit_what_where_py_counted && T.T2_every_sha_the_tool_named_is_on_this_wafer
&& T.T3_tool_and_page_give_every_commit_the_same_keys && T.T4_the_light_was_actually_raised
&& T.T5_that_pixel_carries_the_paths_light !== false;
window.__selftest = T; document.title = 'selftest ' + (T.PASS ? 'PASS' : 'FAIL');
}
// THE CARD, TESTED. A key in the middle of a carried file is tapped by the page itself; the line the
// card shows must be the line that file holds at that number, the marked line must be that one and no
// other, and the panel must be on the screen. A key with no card must say so and show no code at all.
// A RECTANGLE IS NOT A SIGHTING. The link's box was inside the window and the sheet's own overflow
// was hiding it, so the check passed and the photograph showed no link. Ask what is actually at the
// point, which is the question a thumb asks.
const inWindow = r => !!r && r.width > 4 && r.height > 4 && r.top >= -0.5 && r.bottom <= innerHeight + 0.5
&& r.left >= -0.5 && r.right <= innerWidth + 0.5;
const on = el => { if (!el) return false; const r = el.getBoundingClientRect(); if (!inWindow(r)) return false;
const hit = document.elementFromPoint(Math.round(r.left + r.width / 2), Math.round(r.top + r.height / 2));
return !!hit && (hit === el || el.contains(hit) || hit.contains(el)); };
async function cardSelftest(){
const T = { cards_carried: cards.length };
if (!cards.length) { T.PASS = false; T.error = 'no file carries its keys on this page';
window.__selftest = T; document.title = 'selftest FAIL'; return; }
const c = cards[0], j = Math.floor(c.lines / 2), k = c.k0 + j;
T.file = c.path; T.line_asked_for = j + 1; T.key = k;
show(address(k));
for (let i = 0; i < 60 && !cardShown; i++) await new Promise(r => setTimeout(r, 100));
const d = cardShown && cardShown.data;
T.T1_the_card_opened_for_that_key = !!cardShown && cardShown.line === j;
T.T2_the_line_shown_is_the_line_that_file_holds = !!d && typeof d.text[j] === 'string';
const html = card.innerHTML;