From a56897a2ad4a73318ce6a5f370b68f65e46d5975 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 12:12:48 +0000 Subject: [PATCH 1/3] Gravity lab: a spiral galaxy Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015yy9hSCgHQ5WYRZu4JMuW9 --- games.html | 90 ++++++++++++++++++++++++++++++++++++++++++++++--- tests/part5.mjs | 16 +++++++++ 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/games.html b/games.html index 94db2e3..a821aec 100644 --- a/games.html +++ b/games.html @@ -31392,11 +31392,11 @@ Stepped by leapfrog (kick, drift, kick: steady in energy over many orbits), the pull softened over GV_EPS so two bodies passing close do not fly apart in one step; the three bodies stepped finer as they come close (a step a small share of the time two of them take to meet). The boards' share of time, a frame's GV_MS, the framed board first, as Gas lab's. */ - const GV_H = ZG_H, GV_KINDS = ['kepler', 'binary', 'three', 'collapse', 'galaxies', 'column', 'lens', 'jeans', 'real', 'resonance', 'tides', 'sling'], GV_MS = 8, GV_CATCH = 0.1; + const GV_H = ZG_H, GV_KINDS = ['kepler', 'binary', 'three', 'collapse', 'galaxies', 'column', 'lens', 'jeans', 'real', 'resonance', 'tides', 'sling', 'spiral'], GV_MS = 8, GV_CATCH = 0.1; const GVL = ARCADE.difficulty('gravity.level', 'Every board its own sky: more bodies the farther it is from the corner.'); const gvLevel = idx => BOARD_KIT.levelAt(idx, GVL); const GVPICK = labPick('gravity.experiment', GV_KINDS, { kepler: 'Kepler', binary: 'a double star', three: 'three bodies', collapse: 'collapse', galaxies: 'two galaxies', - column: 'the column', lens: 'the lens', jeans: 'clumping', real: 'the real sky', resonance: 'resonances', tides: 'tides', sling: 'a slingshot' }, () => { GVS.clear(); try { fieldItemsChanged(); } catch {} }); + column: 'the column', lens: 'the lens', jeans: 'clumping', real: 'the real sky', resonance: 'resonances', tides: 'tides', sling: 'a slingshot', spiral: 'a spiral galaxy' }, () => { GVS.clear(); try { fieldItemsChanged(); } catch {} }); const GVS = new Map(), GV_CAP = 600; let GVLIVE = null, gvFrame = -1, gvUsed = 0; const GV_PAL = [0x6fb3ff, 0xe8843a, 0x7fdc8a, 0xd77ce0, 0xf2d36b, 0x5fd6d0, 0xff7a7a]; const GV_THREE = ['lagrange', 'eight', 'butterfly', 'moth', 'pythagoras']; @@ -31545,7 +31545,10 @@ // (its potential energy, the far part's ½ Σ m·φ at each body and the near pairs', for the title and the checks: the energy kept is this one's) S.Wpm = W; S.close = Infinity; } - function gvAccel(S){ + function gvAccel(S){ gvAccel0(S); if (S.halo) gvHalo(S); } + // (a halo held fixed, logarithmic: pull V²·r/(r² + rc²) toward the middle, A SPIRAL GALAXY) + function gvHalo(S){ const { V2, rc2 } = S.halo, { n, x, y, z, ax, ay, az } = S; for (let i = 0; i < n; i++){ const f = -V2 / (x[i] * x[i] + y[i] * y[i] + z[i] * z[i] + rc2); ax[i] += f * x[i]; ay[i] += f * y[i]; az[i] += f * z[i]; } } + function gvAccel0(S){ if (S.pm) return gvPMAccel(S); if (S.nm >= GV_TREE && !S.fine) return gvTreeAccel(S); const { n, nm, x, y, z, ax, ay, az, m } = S, e2 = S.eps * S.eps, P = S.per || 0; ax.fill(0); ay.fill(0); az.fill(0); let close = Infinity; @@ -31577,6 +31580,7 @@ for (let i = 0; i < nm; i++){ K += m[i] * (vx[i] * vx[i] + vy[i] * vy[i] + vz[i] * vz[i]) / 2; for (let j = i + 1; j < nm; j++){ let dx = x[j] - x[i], dy = y[j] - y[i], dz = z[j] - z[i]; if (S.per){ const P = S.per; dx -= P * Math.round(dx / P); dy -= P * Math.round(dy / P); dz -= P * Math.round(dz / P); } W -= m[i] * m[j] / Math.sqrt(dx * dx + dy * dy + dz * dz + e2); } } + if (S.halo){ const { V2, rc2 } = S.halo; for (let i = 0; i < nm; i++) W += m[i] * 0.5 * V2 * Math.log(x[i] * x[i] + y[i] * y[i] + z[i] * z[i] + rc2); } // (the halo's own: A SPIRAL GALAXY) return { K, W, E: K + W }; } // what a board watches as it goes: its trails, and Kepler's periods @@ -31668,6 +31672,7 @@ else if (kind === 'resonance') S = rsNew(lv, R); else if (kind === 'tides') S = rcNew(lv, R); else if (kind === 'sling') S = slNew(lv); + else if (kind === 'spiral') S = spNew(lv, R); else { const ng = [300, 500, 750, 1000, 1500][lv - 1], Mc = 10, q = 1.1, Q = 5.0, a = (q + Q) / 2, vQ = Math.sqrt(2 * Mc * (2 / Q - 1 / a)); S = gvBody(2 + 2 * ng, 2); S.eps = 0.12; S.dt = 1 / 300; S.rate = 1; S.ng = ng; @@ -31700,7 +31705,7 @@ if (S){ GVS.delete(key); GVS.set(key, S); } else { const idx = boardIdx(c, r); S = gvNew(idx, gvLevel(idx)); GVS.set(key, S); if (GVS.size > GV_CAP) GVS.delete(GVS.keys().next().value); } return S; } - const GV_RUN = { kepler: 240, binary: 90, collapse: 45, galaxies: 18, jeans: 60, resonance: 240, tides: 60, sling: 1.6 }; // (the slingshot: SL_BACK in, as long out, and a little to see it go) + const GV_RUN = { kepler: 240, binary: 90, collapse: 45, galaxies: 18, jeans: 60, spiral: 24, resonance: 240, tides: 60, sling: 1.6 }; // (the slingshot: SL_BACK in, as long out, and a little to see it go) function gvAdvance(S, framed){ const now = performance.now(), want = Math.min(GV_CATCH, (now - S.at) / 1000) * S.rate; S.at = now; const f = (typeof window !== 'undefined' && window.FIELD_WORLD && window.FIELD_WORLD.frameNo) || Math.floor(now / 16); @@ -31722,6 +31727,7 @@ if (S.kind === 'column') return gcItems(S); if (S.kind === 'lens') return glzItems(S); if (S.kind === 'jeans') return gjItems(S); + if (S.kind === 'spiral') return spItems(S); const out = frameItems(EDGE).slice(); if (S.kind === 'tides'){ rcTogether(S); rcItems(S, out); } if (S.tr) for (const T of S.tr){ const col = S.col[T.i]; for (let k = 0; k < T.p.length; k += 2){ const P = T.p[k]; if (gvIn(P[0], P[1], P[2])) out.push({ kind: 'gvDot', ...UV(P[0], P[1], P[2]), scale: 0.06 * K, color: col }); } } @@ -31909,6 +31915,76 @@ S.crowd = new Uint16Array(n); return S; } // how crowded each body is (others within GJ_NEAR, the box wrapping), and the share in clumps + /* A SPIRAL GALAXY (Dec 1, "What's next", then "1": "A spiral galaxy. With a tree, one disc of 2,000 stars that pull on each other can grow + spiral arms and a central bar by itself"). One disc, its stars all pulling on each other (THE TREE), in a halo held fixed (a logarithmic + one, its pull V²r/(r² + rc²): an even rotation far out, the unseen matter of a real galaxy, not drawn). The stars start spread as a real + disc's light is, falling off as e^(−r/Rd), each on its circle at the speed the disc's pull and the halo's ask for (the disc's measured ring + by ring, less the asymmetric drift), and warm: stirred by as much as Toomre's Q of 1 asks (Toomre, 1964: σR = 3.36·Q·GΣ/κ; well under 1 + a disc breaks into clumps, well over it it stays smooth), 0.7 of that round the centre (κ/2Ω) and half of it up and down. Such a disc is + not still: the ripples its stars' own grain makes are sheared into trailing arms and grown as they turn (swing amplification, Goldreich + and Lynden-Bell, 1965; Toomre, 1981), and how many arms is set by how much of the pull is the disc's own (Carlberg and Freedman, 1985): + the level makes it 25% to 75% at the disc's middle radius (2.2 Rd). Measured (Dec 1): the nearest boards grow five or six thin arms, + broken and flocculent; the middle ones two or three trailing arms by the second turn; the farthest throw a bar across the middle with + two arms within a turn (a disc that holds most of its own pull is unstable to one: Ostriker and Peebles, 1973) and keep the bar. The + arms heat the disc that grows them, and in three or four turns it is too warm to grow more (in a real galaxy new cold stars from gas keep + it going: Sellwood and Carlberg, 1984; a cooling tried here clumped the light discs, and was taken out), so each board starts a new disc + every four turns (GV_RUN, 24 s; SP_TURN, every disc once round at its middle radius in 6 s). The stars are drawn bright where they crowd + more than their ring's mean (the arms), dim elsewhere, the bulge gold. The title counts the arms: the strongest of the 2- to 6-fold + patterns of the stars' angles between 1 and 2.5 Rd, each ring's less what as many stars at random would show, and the bar's 2-fold + pattern inside Rd. */ + const SP_N = [1000, 1250, 1500, 1750, 2000], SP_FD = [0.25, 0.4, 0.5, 0.6, 0.75], SP_RD = 0.8, SP_RMAX = 3.4, SP_RC = 0.5, SP_Q = 1.0, SP_TURN = 6; + function spNew(lv, R){ + const n = SP_N[lv - 1], fd = SP_FD[lv - 1], S = gvBody(n, n); S.eps = 0.06; S.dt = 1 / 80; S.rate = 1; S.fd = fd; + // where the stars lie: e^(−r/Rd), radius drawn by its share of mass (r e^(−r/Rd) dr), out to SP_RMAX + const rm = 2.2 * SP_RD, Md = 1, rr = new Float64Array(n); + for (let i = 0; i < n; i++){ let r; do { r = -SP_RD * Math.log(R() * R()); } while (r > SP_RMAX); const a = R() * 2 * Math.PI; rr[i] = r; + S.x[i] = r * Math.cos(a); S.z[i] = r * Math.sin(a); S.y[i] = 0.04 * Math.sqrt(-2 * Math.log(Math.max(1e-12, R()))) * Math.cos(2 * Math.PI * R()); S.m[i] = Md / n; S.r[i] = 0.035; S.col[i] = 0x9fb4e0; } + // the halo: as much pull at rm as the disc's own there times (1 − fd)/fd + gvAccel0(S); const NB = 24, sum = new Float64Array(NB), cnt = new Float64Array(NB), bin = r => Math.min(NB - 1, Math.floor(r / SP_RMAX * NB)); + for (let i = 0; i < n; i++){ const r = rr[i], b = bin(r); if (r < 1e-6) continue; sum[b] += -(S.ax[i] * S.x[i] + S.az[i] * S.z[i]) / r; cnt[b]++; } + const gD = new Float64Array(NB); for (let b = 0; b < NB; b++) gD[b] = cnt[b] ? sum[b] / cnt[b] : 0; + const gAt = r => { const f = r / SP_RMAX * NB - 0.5, b = Math.max(0, Math.min(NB - 2, Math.floor(f))), w = Math.max(0, Math.min(1, f - b)); return Math.max(0, gD[b] * (1 - w) + gD[b + 1] * w); }; + const gh = gAt(rm) * (1 - fd) / fd, V2 = gh * (rm * rm + SP_RC * SP_RC) / rm; S.halo = { V2, rc2: SP_RC * SP_RC }; + const vc2 = r => r * gAt(r) + V2 * r * r / (r * r + SP_RC * SP_RC); + // warm by Toomre's Q: σR = 3.36·Q·Σ/κ, κ from the rotation curve (κ² = 2Ω/r·d(r²Ω)/dr, by differences) + const Sig = r => Md / (2 * Math.PI * SP_RD * SP_RD) * Math.exp(-r / SP_RD), Om = r => Math.sqrt(vc2(r)) / r; + const kap = r => { const h = 0.02, f = q => q * q * Om(q); return Math.sqrt(Math.max(1e-9, 2 * Om(r) / r * (f(r + h) - f(Math.max(h, r - h))) / (r + h - Math.max(h, r - h)))); }; + const gauss = () => Math.sqrt(-2 * Math.log(Math.max(1e-12, R()))) * Math.cos(2 * Math.PI * R()); + for (let i = 0; i < n; i++){ const r = Math.max(0.05, rr[i]), k = kap(r), sR = Math.min(0.5 * Math.sqrt(vc2(r)), 3.36 * SP_Q * Sig(r) / k), sP = sR * k / (2 * Om(r)); + const vphi = Math.sqrt(Math.max(0.2 * vc2(r), vc2(r) - sR * sR * (1 + r / SP_RD) + sP * sP)), c = S.x[i] / r, sn = S.z[i] / r, vR = sR * gauss(), vp = vphi + sP * gauss(); // (the asymmetric drift: Binney and Tremaine's 4.228, for e^(−r/Rd) and an even σR/σφ) + S.vx[i] = vR * c - vp * sn; S.vz[i] = vR * sn + vp * c; S.vy[i] = 0.5 * sR * gauss(); } + // (every disc once round at its middle radius in SP_TURN seconds: the masses, the halo and the speeds scaled together, which changes nothing but the clock) + const f = Math.pow(2 * Math.PI * rm / Math.sqrt(vc2(rm)) / SP_TURN, 2), sf = Math.sqrt(f); + for (let i = 0; i < n; i++){ S.m[i] *= f; S.vx[i] *= sf; S.vy[i] *= sf; S.vz[i] *= sf; } S.halo.V2 *= f; S.rot = SP_TURN; + return S; + } + // the arms counted: the m-fold pattern of the stars' angles, each ring's share of it, the strongest of m = 2 to 6 between 1 and 2.5 Rd; the bar inside Rd + function spArms(S){ + const A = [0, 0, 0, 0, 0, 0, 0]; let best = 2, nr = 0, br = 0, bi = 0, bn = 0; + const rings = 6, lo = 1 * SP_RD, hi = 2.5 * SP_RD; + for (let k = 0; k < rings; k++){ const r0 = lo + (hi - lo) * k / rings, r1 = lo + (hi - lo) * (k + 1) / rings, re = new Float64Array(7), im = new Float64Array(7); let c = 0; + for (let i = 0; i < S.n; i++){ const r = Math.hypot(S.x[i], S.z[i]); if (r < r0 || r >= r1) continue; const a = Math.atan2(S.z[i], S.x[i]); c++; for (let m = 2; m <= 6; m++){ re[m] += Math.cos(m * a); im[m] += Math.sin(m * a); } } + if (c < 20) continue; nr++; const noise = Math.sqrt(Math.PI / c) / 2; for (let m = 2; m <= 6; m++) A[m] += Math.max(0, Math.hypot(re[m], im[m]) / c - noise); } + for (let i = 0; i < S.n; i++){ const r = Math.hypot(S.x[i], S.z[i]); if (r >= SP_RD) continue; const a = Math.atan2(S.z[i], S.x[i]); br += Math.cos(2 * a); bi += Math.sin(2 * a); bn++; } + for (let m = 2; m <= 6; m++){ A[m] = nr ? A[m] / nr : 0; if (A[m] > A[best]) best = m; } + // (each ring's pattern from its own count c, less what c stars at random angles would show, √π/(2√c): what is left is the stars' own order) + return { m: best, amp: A[best], A: A.slice(2).map(v => +v.toFixed(3)), bar: bn ? Math.max(0, Math.hypot(br, bi) / bn - Math.sqrt(Math.PI / bn) / 2) : 0 }; + } + function spItems(S){ + // (how crowded each star's place is against its ring's mean, read from a polar grid smoothed over its neighbours: one cell holds a few stars, + // so unsmoothed it showed the count's own noise, not the arms) + const out = frameItems(EDGE).slice(), NR = 12, NA = 32, cnt = new Float64Array(NR * NA), sm = new Float64Array(NR * NA), ring = new Float64Array(NR), cell = new Int32Array(S.n); + for (let i = 0; i < S.n; i++){ const r = Math.hypot(S.x[i], S.z[i]), a = Math.atan2(S.z[i], S.x[i]); if (r >= SP_RMAX){ cell[i] = -1; continue; } + const b = Math.floor(r / SP_RMAX * NR), c = Math.floor((a + Math.PI) / (2 * Math.PI) * NA) % NA; cell[i] = b * NA + c; cnt[b * NA + c]++; } + for (let b = 0; b < NR; b++) for (let c = 0; c < NA; c++){ let v = 0, w = 0; + for (let db = -1; db <= 1; db++){ const bb = b + db; if (bb < 0 || bb >= NR) continue; for (let dc = -1; dc <= 1; dc++){ const k = (db || dc) ? 0.5 : 1; v += k * cnt[bb * NA + (c + dc + NA) % NA]; w += k; } } + sm[b * NA + c] = v / w; ring[b] += v / w / NA; } + for (let i = 0; i < S.n; i++){ const x = S.x[i], y = S.y[i], z = S.z[i]; if (!gvIn(x, y, z)) continue; + const q = cell[i], over = q < 0 ? 0 : sm[q] / Math.max(1e-9, ring[Math.floor(q / NA)]), r = Math.hypot(x, z); + const col = r < 0.5 * SP_RD ? 0xffe2a8 : over > 1.3 ? 0xeef3ff : over > 1.05 ? 0xa9bbe4 : 0x55699c; + out.push({ kind: 'gvDot', ...UV(x, y, z), scale: (over > 1.3 ? 0.085 : 0.065) * K, color: col }); } + return out; + } function gjClumped(S){ const { n, x, y, z } = S, P = S.per, c = S.crowd; c.fill(0); const g2 = gjNear(n) ** 2; for (let i = 0; i < n; i++) for (let j = i + 1; j < n; j++){ let dx = x[j] - x[i], dy = y[j] - y[i], dz = z[j] - z[i]; @@ -32136,6 +32212,10 @@ if (S.kind === 'sling'){ const L = S.sl, f = o => o ? o.sun.toFixed(2) + ' against the Sun, ' + o.pl.toFixed(2) + ' against the planet' : '…'; return 'Gravity lab — a slingshot, the probe passing ' + { behind: 'behind the planet', ahead: 'ahead of the planet', over: 'over the planet\'s pole' }[S.pass.side] + ' · coming in: ' + f(L.in) + ' · going out: ' + f(L.out) + (L.in && L.out ? ' · ' + (L.out.sun > L.in.sun ? 'faster' : 'slower') + ' against the Sun by ' + Math.abs(L.out.sun - L.in.sun).toFixed(2) + ', nearly the same against the planet (the Sun\'s pull across the pass makes the rest)' : '') + ' · ' + ts; } + if (S.kind === 'spiral'){ const A = spArms(S); + return 'Gravity lab — a spiral galaxy: a disc of ' + S.n + ' stars pulling on each other, ' + Math.round(100 * S.fd) + '% of the pull at its middle radius its own (the rest an unseen halo) · ' + + (A.amp < 0.06 ? 'still smooth' : (A.m === 2 && A.bar > 0.25 ? 'a bar and two arms' : A.m + ' arms')) + ' (strongest ' + A.m + '-fold, ' + Math.round(100 * A.amp) + '%; the bar ' + Math.round(100 * A.bar) + '%) · ' + + (S.rot ? (S.t / S.rot).toFixed(1) + ' turns at its middle' : '') + ' · ' + ts; } if (S.kind === 'jeans') return 'Gravity lab — clumping: ' + S.n + ' bodies spread evenly, warm, in a box that wraps round · Jeans length ' + S.lamJ.toFixed(1) + ', half the box: ripples wider than it fall in · ' + Math.round(100 * (S.clumped || 0)) + '% in clumps (gold) · ' + (gvEnergy(S).K / S.K0).toFixed(2) + '× as warm as at the start (gravity heats what it gathers) · ' + ts; if (S.kind === 'lens'){ const u = glzU(S), nm = ['a point mass', 'a cluster of 40 inside the ring (the same ring: only the mass inside counts)', 'two masses', 'a point mass before a galaxy', 'a cluster of 30 wider than the ring before a galaxy'][S.lv - 1]; @@ -32185,7 +32265,7 @@ const dot = (x, y, r, c) => { ctx.fillStyle = c; ctx.beginPath(); ctx.arc(x * sz, y * sz, r * sz, 0, 7); ctx.fill(); }; dot(0.5, 0.52, 0.08, '#f2c14e'); dot(0.83, 0.42, 0.04, '#6fb3ff'); dot(0.33, 0.6, 0.03, '#e8843a'); }, - _debug: { get LABW(){ return LABW; }, labThin, gvFFT3, GVS, GVPICK, gvNew, gvStep, gvAccel, gvH, gvEnergy, gvPulled, gvStir, gvSDfit, grNew, GR_SYS, rsNew, rsCount, rcNew, rcTogether, rcLim, slNew, SL_PASS, gjNew, gjClumped, gcNew, gcColumnPull, gcNewton, gcProbe, glzNew, glzTrace, glzMap, glzSource, GLZ_RE, GLZ_N, GLZ_W, GC_BODIES, gvOf, gvItems, gvAdvance, GV_KINDS, GV_THREE, GV_H, levelOf: (c, r) => gvLevel(boardIdx(c, r)), get LIVE(){ return GVLIVE; }, set LIVE(v){ GVLIVE = v; } }, + _debug: { get LABW(){ return LABW; }, labThin, gvFFT3, GVS, GVPICK, gvNew, gvStep, gvAccel, gvH, gvEnergy, gvPulled, gvStir, gvSDfit, grNew, GR_SYS, rsNew, rsCount, rcNew, rcTogether, rcLim, slNew, SL_PASS, gjNew, gjClumped, spNew, spArms, gvTitle, gcNew, gcColumnPull, gcNewton, gcProbe, glzNew, glzTrace, glzMap, glzSource, GLZ_RE, GLZ_N, GLZ_W, GC_BODIES, gvOf, gvItems, gvAdvance, GV_KINDS, GV_THREE, GV_H, levelOf: (c, r) => gvLevel(boardIdx(c, r)), get LIVE(){ return GVLIVE; }, set LIVE(v){ GVLIVE = v; } }, }; /* ═══ CHARGE LAB (Dec 1: "What's next", then "A third lab"): electricity and magnetism in the same cube, here in its closure as Gas lab and Gravity lab are. Charges push and pull by Coulomb's law (k = 1: a = q·E/m, E = Σ qj·r/|r|³) and are turned by a magnetic field (the diff --git a/tests/part5.mjs b/tests/part5.mjs index fb8a566..4adb3e6 100644 --- a/tests/part5.mjs +++ b/tests/part5.mjs @@ -2040,6 +2040,22 @@ const game = { title: 'Words', size: l => 5 + Math.ceil(l / 2), console.log(`${ok ? 'ok ' : 'FAIL'} gravity lab, more bodies: the tree's pulls against every pair's for ${bh.n} bodies, ${bh.tree} apart; the wrapping box's pull (tree and mesh) of one mass against Newton's at 0.15, 0.4, 1, 1.5 and 2: ${bh.mesh}; ${bh.pool} lab worker(s); a far board's ${bh.thin.all} pieces ${bh.thin.at60} at 60 px (area kept ${bh.thin.area}), ${bh.thin.at300} at 300`); } + // (Dec 1, "1": a spiral galaxy): a disc of stars pulling on each other in a fixed halo, smooth at the start; by its first turn the heaviest + // (75% of the pull its own) throws a bar and two arms, the lightest (25%) many thin ones and no bar; its title counts them + { + current = 'gravity'; + await page.evaluate(() => window.setFieldApp(window.FIELD_APPS.find(a => a.id === 'gravity'))); + const sp = await page.evaluate(() => { const D = window.getFieldApp()._debug, out = { kind: D.GV_KINDS.includes('spiral'), runs: [] }; + for (const idx of [1, 2, 3]) for (const lv of [1, 5]){ const S = D.gvNew(idx, lv, 0, 'spiral'), a0 = D.spArms(S).amp; while (S.t < 6) D.gvStep(S, D.gvH(S)); const A = D.spArms(S); + out.runs.push({ idx, lv, n: S.n, a0: +a0.toFixed(2), m: A.m, amp: +A.amp.toFixed(2), bar: +A.bar.toFixed(2) }); if (idx === 1 && lv === 5) out.title = D.gvTitle(S); } + return out; }); + const H = sp.runs.filter(r => r.lv === 5), L = sp.runs.filter(r => r.lv === 1); + const ok = sp.kind && sp.runs.every(r => r.a0 < 0.08) && H.every(r => r.m === 2 && r.amp > 0.2 && r.bar > 0.2) && L.every(r => r.bar < 0.1) && L.filter(r => r.m >= 4).length >= 2 + && /^Gravity lab — a spiral galaxy: a disc of 2000 stars/.test(sp.title || ''); + if (!ok) failures.push('[gravity spiral] ' + JSON.stringify(sp)); + console.log(`${ok ? 'ok ' : 'FAIL'} gravity lab, a spiral galaxy: smooth at the start (${sp.runs.map(r => r.a0).join(',')}); by 6 s the heavy disc ${H.map(r => r.m + '-fold ' + r.amp + ', bar ' + r.bar).join('; ')}; the light disc ${L.map(r => r.m + '-fold ' + r.amp + ', bar ' + r.bar).join('; ')}; "${(sp.title || '').slice(0, 120)}"`); + } + } catch (e){ failures.push(`[${current}] ${e.message}`); } From cabb389cd8ebce597da8ff1dd05debfeb8d1f770 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 12:13:00 +0000 Subject: [PATCH 2/3] Docs: a spiral galaxy Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015yy9hSCgHQ5WYRZu4JMuW9 --- docs/tables.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/tables.md b/docs/tables.md index 349acd0..3c54f51 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -2093,3 +2093,19 @@ one mass falling as 1/r² near it (1.014, 0.986, 0.934 at 1, 1.5 and 2: the box' change the drift: it is the split's, not the step's. The cost is about three times the mesh's: 23 ms a step for 2,000 clumped bodies (five transforms 9 ms, the near pairs most of the rest), 550 to 1,000 ms of work a simulated second at 400 to 2,000 bodies, carried by the workers. + +### A spiral galaxy (1 Dec 2026) +"What's next", then "1": "A spiral galaxy. With a tree, one disc of 2,000 stars that pull on each other can grow spiral arms and a central +bar by itself." Gravity lab's thirteenth experiment (`spiral`, A SPIRAL GALAXY, `spNew`, `spArms`, `spItems`): 1,000 to 2,000 stars by the +level in one disc, e^(−r/Rd), all pulling on each other through the tree, in a fixed logarithmic halo (`S.halo`, `gvHalo`, its potential in +`gvEnergy`), each star on its circle at the speed its measured pull asks (less the asymmetric drift) and stirred as Toomre's Q of 1 asks. The +level sets the disc's share of the pull at 2.2 Rd, 25% to 75%; every disc is scaled to turn once in 6 s at that radius and starts again after +four turns (24 s). Drawn: the stars bright where they crowd above their ring's mean on a smoothed polar grid (the arms), the bulge gold. +What it does, measured on three boards each: smooth at the start (the pattern above the counting noise 0.02–0.05); by 6 s the heavy disc +(75%) 2-fold at 0.24–0.51 with a bar of 0.29–0.51, and the light disc (25%) strongest at 5 or 6 fold with no bar; the middle discs two or +three trailing arms by the second turn. Tried and taken out: Q 1.3 (arms barely above the noise), and a cooling to keep the arms coming +(Sellwood and Carlberg's gas, eased toward circles over two turns: cooled to circles the heavy disc fell into clumps and flung its stars +out; cooled only back to its starting stir, the light disc clumped); without it the arms heat the disc and fade in three or four turns, which +is what star-only discs do (Sellwood, 2011), hence the restart. Its cost: 200 to 600 ms of work a simulated second (1,000 to 2,000 stars at +80 steps a second). Part 5 checks the start smooth, the heavy disc's two arms and bar and the light disc's many arms and no bar at 6 s on +three boards, and the title. From d0f4ed7ff792de665af78fd1d073fda8ee4a517d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 12:14:39 +0000 Subject: [PATCH 3/3] Part 5: the resonance check's three kinds Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015yy9hSCgHQ5WYRZu4JMuW9 --- tests/part5.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/part5.mjs b/tests/part5.mjs index 4adb3e6..8bc9df0 100644 --- a/tests/part5.mjs +++ b/tests/part5.mjs @@ -1938,7 +1938,7 @@ const game = { title: 'Words', size: l => 5 + Math.ceil(l / 2), // orbits cross; bodies locked 3:2 keep away and those not locked do not; a rubble moon holds outside its limit and comes apart inside it; // a probe passing behind a planet leaves faster against the Sun, ahead of it slower, against the planet nearly the same { - const rs = await page.evaluate(() => { const D = window.getFieldApp()._debug, out = { kinds: D.GV_KINDS.slice(9).join() }; const run = (S, t) => { while (S.t < t) D.gvStep(S, D.gvH(S)); }; + const rs = await page.evaluate(() => { const D = window.getFieldApp()._debug, out = { kinds: D.GV_KINDS.slice(9, 12).join() }; const run = (S, t) => { while (S.t < t) D.gvStep(S, D.gvH(S)); }; const Tr = D.gvNew(9, 1); run(Tr, 60); const c = D.rsCount(Tr); out.troj = c.a / c.ta; const Pl = D.gvNew(9, 3); run(Pl, 60); out.pluto = +Pl.near.toFixed(1); const Pn = D.gvNew(9, 4); run(Pn, 60); const p = D.rsCount(Pn); out.lock = [p.a, p.ta, p.b, p.tb];