diff --git a/CLAUDE.md b/CLAUDE.md index 0268908..89c6f18 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -103,7 +103,7 @@ a new game or a change keeps to them. - **Trick shots' worker** is made from its own text up to "IN THE FIELD": nothing of a kit may go above that line. - **Draw only what is seen, in full.** Every board on the screen has all its pieces at any - size; detail fades by the kits' morphing kinds, never by swapping pieces. + size; detail fades by the kits' morphing kinds, never by swapping pieces. A far lab board's bodies that share a pixel are one piece, as large as their areas added (Dec 1, `labThin`). ## Shared with draw: change with care `games.html` carries two blocks of draw's **verbatim**, inside `const TVF_CURVE = (() => { … })()` before `GOLF_APP`: diff --git a/docs/tables.md b/docs/tables.md index 9b08d66..349acd0 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -2074,3 +2074,22 @@ pair summed, so the softening's and not the tree's; its energy kept to 1.6%. Clu 2,000, its warm control still even; its energy drifts 6–14% over 30 s as clumps reach a cell's size (the mesh's known weakness), so part 5's bound on it went from 1% to 20%. Part 5 also checks the tree's pulls against every pair's for the 750-body collapse (under 3% apart), the mesh's pull of one mass falling as 1/r² near it (1.014, 0.986, 0.934 at 1, 1.5 and 2: the box's copies pull back the farther out), and that the pool has its workers. A first run found the pool choosing its worker from a board's key as a number, when the key is "c_r": it now goes by column and row. + +### A pixel's worth on a far board, and the near pull summed (TreePM) (1 Dec 2026) +"What's next", then "1 2": far boards drawn more cheaply, and the clumping box's pull made right below a grid cell. +- **Far boards.** Measured zoomed out over Gravity lab, the small dots (`gvDot`) reached the field's 48,000 a kind by the middle distance + (67,000 asked for at zoom 600, 118,000 at 900), and every board past them stood with no dots at all. Two changes: a board under 200 px + across (not the one brought in) has its bodies of one kind and colour that fall in one 2-pixel square drawn as one, at the first one's + place, as large as their areas added (`labThin`, A PIXEL'S WORTH ON A SMALL BOARD, in the labs, so the workers do it); and Gravity lab + gives its small dots room for 240,000 (`itemCaps`). At zoom 900 the dots asked for came to 66,000 drawn of 114,000 merged from, under the new + room. Every pixel with a body still has one; above 200 px every body is its own piece. The frame and glass are untouched. (CLAUDE.md's + "every board on the screen has all its pieces at any size" is kept in this sense: bodies a board's pixel cannot tell apart are one piece.) +- **TreePM.** On the mesh alone (THE MESH) a clump that shrank to a cell lost its pull finer than a cell. The pull is now split by a Gaussian + one cell wide: the mesh carries the far part (each wave times e^(−k²rs²), the cloud in cell's blur divided back out, the slope taken from the + waves), and pairs nearer than 4.5 rs are summed exactly with erfc(r/2rs) + (r/rs√π)e^(−r²/4rs²), found through cells as wide as that reach, + the two factors from a table. One mass's pull against Newton's at 0.15 to 1.2 (under a cell and past it) within 5% (1.25 cells: 3%, but + the energy drifted twice as much); the energy over 30 s 4% of the start's (was 6–14%), half a percent of the warmed gas's motion (the gas + starts with next to no energy of position, so part 5 now reads it both ways: under 10% and under 1%). Halving or quartering the step did not + 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. diff --git a/games.html b/games.html index c5164f9..94db2e3 100644 --- a/games.html +++ b/games.html @@ -31053,6 +31053,26 @@ // >>> LABS: Gas lab, Gravity lab and Charge lab, from here to its end mark, are also the labs' worker's text (`labWorkerSrc`, LABS ON // THEIR OWN CORE below): nothing outside them may be used here when the worker runs it but the zero-g engine, the cube's drawing and the // stand-ins the worker gives (a level, a seed, no sound, no menu); anything else only inside a function the worker never calls. + /* A PIXEL'S WORTH ON A SMALL BOARD (Dec 1, "What's next", then "1 2": "Far boards: … draw its stars as one point cloud or as fewer, heavier + dots"). Since the tree (THE TREE, a thousand bodies falling together, two thousand clumping) a far board holds more bodies than it has pixels, + and the field keeps 48,000 pieces of a kind: zoomed half way out over Gravity lab every small dot in view was 48,000 by the middle distance and + the boards past them stood empty of dots. A board under LAB_THIN_PX across (not the one brought in) now has the pieces of one kind and colour + that fall in one square of LAB_THIN_CELL pixels drawn as one, at the first one's place and as large as their areas added (so a clump reads as + heavier, not as one body), the frame and glass untouched. What is seen is kept: every pixel with a body in it still has one. Above the size + every body is its own piece, as before. */ + const LAB_THIN_PX = 200, LAB_THIN_CELL = 2, LAB_THIN_KINDS = new Set(['glBall', 'glDot', 'gvBall', 'gvStar', 'gvDot', 'gvMist']); + function labThin(L, bp){ + if (!(bp > 0) || bp >= LAB_THIN_PX || !L || L.length < 64) return L; + const g = LAB_THIN_CELL / bp, out = [], at = new Map(); + for (const it of L){ + if (!LAB_THIN_KINDS.has(it.kind) || it.sx != null){ out.push(it); continue; } + const k = it.kind + '|' + it.color + '|' + Math.floor(it.u / g) + '|' + Math.floor(it.v / g) + '|' + Math.floor((it.lift || 0) / g); + const j = at.get(k); + if (j == null){ at.set(k, out.length); out.push(it); continue; } + const o = out[j]; out[j] = { ...o, scale: Math.sqrt(o.scale * o.scale + it.scale * it.scale) }; + } + return out; + } /* ═══ GAS LAB (Nov 30: "Seems to me that this demo could be a playground to visualize many 3d phenomenon", then "New app, start with the gas and mixing"). Zero-g pool's cube made a playground for what many balls in a box do: its frame, glass, framing, balls and shadows, here in its closure, nothing copied. Every board is an experiment, by its number: even boards a gas, odd boards mixing; the level by its ring sets how many @@ -31325,7 +31345,7 @@ glPlate: T => { const g = new T.BoxGeometry(1, 1, 1); g.userData.opacity = 0.35; return g; }, }, cellGrid(){ return { n: 1, colors: [BASE] }; }, - cellItems(c, r){ return LABW.items('gas', c, r); }, + cellItems(c, r, bp){ return LABW.items('gas', c, r, bp); }, menu: [{ head: 'Gas lab', items: [{ label: GDL.item.label, title: GDL.item.title, on(){ GDL.item.on(); GLS.clear(); try { fieldItemsChanged(); } catch {} } }, GPICK.item, GSND.item] }], cellTitle(c, r){ return LABW.title('gas', c, r); }, onReset(c, r){ GLS.delete(gkey(c, r)); LABW.reset('gas', gkey(c, r)); GLIVE = { c, r }; try { fieldItemsChanged(); } catch {} return true; }, @@ -31467,32 +31487,63 @@ for (let a = 0; a < G; a++) for (let b = 0; b < G; b++){ const o = a * s2 + b * s3; for (let c = 0; c < G; c++){ lr[c] = re[o + c * s1]; li[c] = im[o + c * s1]; } gvFFT(lr, li, G, inv); for (let c = 0; c < G; c++){ re[o + c * s1] = lr[c]; im[o + c * s1] = li[c]; } } } + /* (Dec 1, "What's next", then "1 2": the mesh made a tree and a mesh, TreePM, as cosmology's codes have it (Xu 1995; Bagla 2002; GADGET-2, + Springel 2005). On the mesh alone a clump that shrank to a cell lost its pull finer than a cell, and the energy drifted 6–14% in 30 s. Now + the pull is split by a Gaussian of width GV_RS cells: the mesh carries the far part only (each wave's potential times e^(−k²rs²), with the + cloud in cell's own blur divided back out and the slope taken from the waves, not from neighbouring cells), and every pair nearer than + GV_RCUT·rs is summed exactly for the near part, 1/r² times erfc(r/2rs) + (r/rs√π)·e^(−r²/4rs²), found through cells as large as that + reach. The two parts add to Newton's pull at every distance, the softening kept. */ + const GV_RS = 1, GV_RCUT = 4.5, GV_TAB = { n: 2048 }; + // (Abramowitz and Stegun's 7.1.26, to 1.5·10⁻⁷) + const gvErfc = x => { const t = 1 / (1 + 0.3275911 * x); return t * (0.254829592 + t * (-0.284496736 + t * (1.421413741 + t * (-1.453152027 + t * 1.061405429)))) * Math.exp(-x * x); }; function gvPMAccel(S){ - const { n, x, y, z, ax, ay, az, m } = S, G = GV_PM, P = S.per, h = P / G, N3 = G * G * G; - let M = S.M3; if (!M) M = S.M3 = { re: new Float64Array(N3), im: new Float64Array(N3), phi: new Float64Array(N3), gk: null }; - const { re, im, phi } = M; re.fill(0); im.fill(0); + const { n, x, y, z, ax, ay, az, m } = S, G = GV_PM, P = S.per, h = P / G, N3 = G * G * G, rs = (S.rsK || GV_RS) * h, e2 = S.eps * S.eps, RC = S.rcK || GV_RCUT; + let M = S.M3; if (!M) M = S.M3 = { re: new Float64Array(N3), im: new Float64Array(N3), fr: [0, 1, 2].map(() => new Float64Array(N3)), fi: new Float64Array(N3), pr: new Float64Array(N3), pi: new Float64Array(N3) }; + const { re, im, fr, fi, pr, pi } = M; re.fill(0); im.fill(0); // the cells about each body and its share in each (cloud in cell) const cic = (i, f) => { const u = (x[i] + P / 2) / h - 0.5, v = (y[i] + P / 2) / h - 0.5, w = (z[i] + P / 2) / h - 0.5, i0 = Math.floor(u), j0 = Math.floor(v), k0 = Math.floor(w), du = u - i0, dv = v - j0, dw = w - k0; for (let a = 0; a < 2; a++) for (let b = 0; b < 2; b++) for (let c = 0; c < 2; c++){ const q = (((i0 + a) % G + G) % G) + G * ((((j0 + b) % G + G) % G) + G * (((k0 + c) % G + G) % G)); f(q, (a ? du : 1 - du) * (b ? dv : 1 - dv) * (c ? dw : 1 - dw)); } }; for (let i = 0; i < n; i++) cic(i, (q, w) => { re[q] += m[i] * w / (h * h * h); }); gvFFT3(re, im, G, false); - // each wave's potential: −4πG·ρ_k / k², the mean (k = 0) none; with the cloud-in-cell's own smoothing left in (it softens a cell) + // each wave's far potential, −4π·ρ_k·e^(−k²rs²)/k² over the cloud in cell's blur twice (sharing and reading back), the mean none; and its slope + const K = [], sinc = t => t ? Math.sin(t) / t : 1; for (let c = 0; c < G; c++) for (let b = 0; b < G; b++) for (let a = 0; a < G; a++){ const q = a + G * (b + G * c); - if (!a && !b && !c){ re[q] = im[q] = 0; continue; } - const kx = 2 * Math.PI / P * (a <= G / 2 ? a : a - G), ky = 2 * Math.PI / P * (b <= G / 2 ? b : b - G), kz = 2 * Math.PI / P * (c <= G / 2 ? c : c - G), f = -4 * Math.PI / (kx * kx + ky * ky + kz * kz); - re[q] *= f; im[q] *= f; } - gvFFT3(re, im, G, true); for (let q = 0; q < N3; q++) phi[q] = re[q] / N3; - // the pull: the potential's slope across each cell's neighbours, given back to each body as its mass was shared - const at = (a, b, c) => phi[((a % G + G) % G) + G * (((b % G + G) % G) + G * ((c % G + G) % G))]; - for (let i = 0; i < n; i++){ let gx = 0, gy = 0, gz = 0; - const u = (x[i] + P / 2) / h - 0.5, v = (y[i] + P / 2) / h - 0.5, w = (z[i] + P / 2) / h - 0.5, i0 = Math.floor(u), j0 = Math.floor(v), k0 = Math.floor(w), du = u - i0, dv = v - j0, dw = w - k0; - for (let a = 0; a < 2; a++) for (let b = 0; b < 2; b++) for (let c = 0; c < 2; c++){ const A = i0 + a, B = j0 + b, C = k0 + c, wt = (a ? du : 1 - du) * (b ? dv : 1 - dv) * (c ? dw : 1 - dw); - gx -= wt * (at(A + 1, B, C) - at(A - 1, B, C)) / (2 * h); gy -= wt * (at(A, B + 1, C) - at(A, B - 1, C)) / (2 * h); gz -= wt * (at(A, B, C + 1) - at(A, B, C - 1)) / (2 * h); } - ax[i] = gx; ay[i] = gy; az[i] = gz; } - // (its potential energy, ½ Σ m·φ at each body, for the title and the checks: the mesh's own, so the energy kept is the mesh's) - let W = 0; for (let i = 0; i < n; i++) cic(i, (q, wt) => { W += 0.5 * m[i] * wt * phi[q]; }); S.Wpm = W; - S.close = Infinity; + if (!a && !b && !c){ pr[q] = pi[q] = 0; fr[0][q] = fr[1][q] = fr[2][q] = 0; continue; } + const kx = 2 * Math.PI / P * (a < G / 2 ? a : a - G), ky = 2 * Math.PI / P * (b < G / 2 ? b : b - G), kz = 2 * Math.PI / P * (c < G / 2 ? c : c - G), k2 = kx * kx + ky * ky + kz * kz; + const wc = (sinc(kx * h / 2) * sinc(ky * h / 2) * sinc(kz * h / 2)) ** 2, f = -4 * Math.PI * Math.exp(-k2 * rs * rs) / (k2 * wc * wc); + pr[q] = re[q] * f; pi[q] = im[q] * f; + // (−i·k·φ_k, the pull's wave, each way; a wave at the grid's own edge, G/2, has no slope it can show) + K[0] = a === G / 2 ? 0 : kx; K[1] = b === G / 2 ? 0 : ky; K[2] = c === G / 2 ? 0 : kz; + for (let d = 0; d < 3; d++) fr[d][q] = K[d]; } + for (let d = 0; d < 3; d++){ const F = fr[d]; for (let q = 0; q < N3; q++){ const k = F[q]; F[q] = k * pi[q]; fi[q] = -k * pr[q]; } + gvFFT3(F, fi, G, true); for (let q = 0; q < N3; q++) F[q] /= N3; } + gvFFT3(pr, pi, G, true); for (let q = 0; q < N3; q++) pr[q] /= N3; + let W = 0; + for (let i = 0; i < n; i++){ let gx = 0, gy = 0, gz = 0, ph = 0; cic(i, (q, wt) => { gx += wt * fr[0][q]; gy += wt * fr[1][q]; gz += wt * fr[2][q]; ph += wt * pr[q]; }); + ax[i] = gx; ay[i] = gy; az[i] = gz; W += 0.5 * m[i] * (ph + m[i] / (Math.sqrt(Math.PI) * rs)); } // (less each body's own far potential, −m/(√π·rs)) + // the near part, pair by pair, through cells as wide as the reach + const rc = RC * rs, nc = Math.max(3, Math.floor(P / rc)), cs = P / nc, head = M.head && M.head.length === nc * nc * nc ? M.head : (M.head = new Int32Array(nc * nc * nc)), next = M.next && M.next.length >= n ? M.next : (M.next = new Int32Array(n)); + head.fill(-1); const cell = i => { const a = Math.min(nc - 1, Math.floor((x[i] + P / 2) / cs)), b = Math.min(nc - 1, Math.floor((y[i] + P / 2) / cs)), c = Math.min(nc - 1, Math.floor((z[i] + P / 2) / cs)); return [(a + nc) % nc, (b + nc) % nc, (c + nc) % nc]; }; + const at = new Int32Array(3 * n); for (let i = 0; i < n; i++){ const [a, b, c] = cell(i); at[3 * i] = a; at[3 * i + 1] = b; at[3 * i + 2] = c; const q = a + nc * (b + nc * c); next[i] = head[q]; head[q] = i; } + // (the near part's two factors, erfc(u) and erfc(u) + (2u/√π)·e^(−u²), u = r/2rs, from a table of GV_TAB steps to the reach, read between steps) + if (!GV_TAB.ec || GV_TAB.rc !== RC){ GV_TAB.rc = RC; GV_TAB.ec = new Float64Array(GV_TAB.n + 2); GV_TAB.sh = new Float64Array(GV_TAB.n + 2); const U = RC / 2; + for (let k = 0; k <= GV_TAB.n + 1; k++){ const u = k * U / GV_TAB.n, ec = gvErfc(u); GV_TAB.ec[k] = ec; GV_TAB.sh[k] = ec + 2 * u / Math.sqrt(Math.PI) * Math.exp(-u * u); } } + const TE = GV_TAB.ec, TS = GV_TAB.sh, tk = GV_TAB.n / rc, rc2 = rc * rc; + for (let i = 0; i < n; i++){ const a0 = at[3 * i], b0 = at[3 * i + 1], c0 = at[3 * i + 2], xi = x[i], yi = y[i], zi = z[i]; let gx = 0, gy = 0, gz = 0; + for (let dc = -1; dc <= 1; dc++) for (let db = -1; db <= 1; db++) for (let da = -1; da <= 1; da++){ + // (a neighbouring cell across the box's edge is its nearest copy: shifted by the box once, not each pair rounded) + const A = a0 + da, B = b0 + db, C = c0 + dc, q = (A + nc) % nc + nc * ((B + nc) % nc + nc * ((C + nc) % nc)); + const sx = A < 0 ? -P : A >= nc ? P : 0, sy = B < 0 ? -P : B >= nc ? P : 0, sz = C < 0 ? -P : C >= nc ? P : 0; + for (let j = head[q]; j >= 0; j = next[j]){ if (j <= i) continue; + const dx = x[j] + sx - xi, dy = y[j] + sy - yi, dz = z[j] + sz - zi, d2 = dx * dx + dy * dy + dz * dz; if (d2 >= rc2) continue; + const f = Math.sqrt(d2) * tk, k0 = f | 0, w = f - k0, ec = TE[k0] + w * (TE[k0 + 1] - TE[k0]), sh = TS[k0] + w * (TS[k0 + 1] - TS[k0]); + const q2 = d2 + e2, iq = 1 / Math.sqrt(q2), k = sh * iq * iq * iq; + gx += dx * m[j] * k; gy += dy * m[j] * k; gz += dz * m[j] * k; ax[j] -= dx * m[i] * k; ay[j] -= dy * m[i] * k; az[j] -= dz * m[i] * k; + W -= m[i] * m[j] * ec * iq; } } + ax[i] += gx; ay[i] += gy; az[i] += gz; } + // (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){ if (S.pm) return gvPMAccel(S); @@ -31840,7 +31891,8 @@ radiates away). The box's wrapping is the standard toy (the nearest copy only, not the endless sum of all of them), right for clumps much smaller than the box. Starts again after 60 s. Since Dec 1 its pull is the mesh's (THE MESH, every copy of the box, not the nearest alone), stepped 40 times a second: from 0 to 29–39% in clumps by 20–30 s and 7 to 9 times as warm, at 400, 1,000 and 2,000 bodies alike, the warm - gas still even; the energy drifts 6–14% over 30 s as clumps shrink to a cell (the mesh's own weakness, its pulls smoothed over a cell). */ + gas still even; on the mesh alone the energy drifted 6–14% of the start's over 30 s as clumps shrank to a cell, and with the near pairs + summed (TreePM, below THE MESH) 4%, half a percent of the warmed gas's motion. */ const GJ_N = [400, 700, 1000, 1500, 2000], GJ_M = 6, GJ_K = 5; // (near: the radius in which an even spread would put 0.3 of another body, so GJ_K or more there is seventeen times the mean density) const gjNear = n => Math.cbrt(0.3 * Math.pow(2 * GV_H, 3) * 3 / (4 * Math.PI * n)); @@ -32118,7 +32170,9 @@ gvMist: T => { const g = new T.SphereGeometry(0.5, 8, 6); g.userData.opacity = 0.3; g.userData.unlit = true; return g; }, }, cellGrid(){ return { n: 1, colors: [BASE] }; }, - cellItems(c, r){ return LABW.items('gravity', c, r); }, + cellItems(c, r, bp){ return LABW.items('gravity', c, r, bp); }, + // (more room for the small dots than the field's 48,000 a kind: a field of boards of a thousand bodies each, A PIXEL'S WORTH, Dec 1) + itemCaps: kind => kind === 'gvDot' ? 240000 : 0, menu: [{ head: 'Gravity lab', items: [{ label: GVL.item.label, title: GVL.item.title, on(){ GVL.item.on(); GVS.clear(); try { fieldItemsChanged(); } catch {} } }, GVPICK.item] }], cellTitle(c, r){ return LABW.title('gravity', c, r); }, onReset(c, r){ GVS.delete(gkey(c, r)); LABW.reset('gravity', gkey(c, r)); GVLIVE = { c, r }; try { fieldItemsChanged(); } catch {} return true; }, @@ -32131,7 +32185,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; }, 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, 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 @@ -32432,7 +32486,7 @@ gvDot: T => { const g = new T.SphereGeometry(0.5, 6, 4); g.userData.unlit = true; return g; }, }, cellGrid(){ return { n: 1, colors: [BASE] }; }, - cellItems(c, r){ return LABW.items('charge', c, r); }, + cellItems(c, r, bp){ return LABW.items('charge', c, r, bp); }, menu: [{ head: 'Charge lab', items: [{ label: CHL.item.label, title: CHL.item.title, on(){ CHL.item.on(); CHS.clear(); try { fieldItemsChanged(); } catch {} } }, CHPICK.item] }], cellTitle(c, r){ return LABW.title('charge', c, r); }, onReset(c, r){ CHS.delete(gkey(c, r)); LABW.reset('charge', gkey(c, r)); CHLIVE = { c, r }; try { fieldItemsChanged(); } catch {} return true; }, @@ -32487,7 +32541,7 @@ d.boards.sort((a, b) => (b.framed - a.framed) || ((SERVED.get(a.key) || 0) - (SERVED.get(b.key) || 0))); for (const b of d.boards){ if (!b.framed && performance.now() - t0 > LAB_BUDGET) break; SERVED.set(b.key, performance.now()); let S = L.M.get(b.key); if (!S || S.kind !== b.kind || S.lv !== b.lv){ S = L.New(b.idx, b.lv, b.kind); } L.M.delete(b.key); L.M.set(b.key, S); - L.adv(S, b.framed); const f = pack(L.items(S)); bufs.push(f.buffer); + L.adv(S, b.framed); const f = pack(b.framed ? L.items(S) : labThin(L.items(S), b.bp)); bufs.push(f.buffer); const o = { key: b.key, f }; if (b.title) o.title = L.title(S); if (b.framed && d.lab === 'gas'){ o.snd = { kind: S.kind, hits: S.hits, hitV: S.hitV, bigHit: S.bigHit, mixed: S.mixed }; S.bigHit = 0; } out.push(o); } @@ -32531,18 +32585,18 @@ } // (a board's key is "c_r", a string: the worker is chosen by its column and row, so neighbours go to different workers) const workerOf = key => { const [c, r] = String(key).split('_').map(Number); return W.ws[(((c * 7 + r * 3) % W.ws.length) + W.ws.length) % W.ws.length] || W.ws[0]; }; - function ask(lab, c, r, title){ + function ask(lab, c, r, title, bp){ const L = LAB[lab], key = gkey(c, r), idx = boardIdx(c, r), live = L.live(); if (W.lab !== lab){ W.lab = lab; W.items.clear(); W.titles.clear(); W.ear.clear(); for (const X of W.ws){ X.want.clear(); X.pending = false; } } const X = workerOf(key), was = X.want.get(key), framed = !!(live && live.c === c && live.r === r); - X.want.set(key, { key, idx, lv: L.level(idx), kind: L.pick.kindOf(idx), framed, title: title || (was && was.title) || framed }); + X.want.set(key, { key, idx, lv: L.level(idx), kind: L.pick.kindOf(idx), framed, title: title || (was && was.title) || framed, bp: bp || (was && was.bp) || 0 }); flush(); return key; } - function items(lab, c, r){ + function items(lab, c, r, bp){ const L = LAB[lab]; if (!start()){ const S = L.of(c, r), live = L.live(), framed = !!(live && live.c === c && live.r === r), want = L.adv(S, framed); - if (framed && lab === 'gas' && want) glSound(S, want); return L.items(S); } - const key = ask(lab, c, r, false); return W.items.get(key) || frameItems(EDGE); + if (framed && lab === 'gas' && want) glSound(S, want); return framed ? L.items(S) : labThin(L.items(S), bp); } + const key = ask(lab, c, r, false, bp); return W.items.get(key) || frameItems(EDGE); } function title(lab, c, r){ const L = LAB[lab]; if (!start()) return L.title(L.of(c, r)); diff --git a/tests/part5.mjs b/tests/part5.mjs index 2f13e18..fb8a566 100644 --- a/tests/part5.mjs +++ b/tests/part5.mjs @@ -1912,12 +1912,12 @@ const game = { title: 'Words', size: l => 5 + Math.ceil(l / 2), { const gj = await page.evaluate(() => { const D = window.getFieldApp()._debug, out = { kind: D.GV_KINDS[7] }; const S = D.gvNew(7, 3); out.c0 = D.gjClumped(S); while (S.t < 30) D.gvStep(S, D.gvH(S)); - out.c30 = +D.gjClumped(S).toFixed(2); out.warm = +(D.gvEnergy(S).K / S.K0).toFixed(1); out.dE = +Math.abs(D.gvEnergy(S).E / S.E0 - 1).toFixed(4); + out.c30 = +D.gjClumped(S).toFixed(2); out.warm = +(D.gvEnergy(S).K / S.K0).toFixed(1); out.dE = +Math.abs(D.gvEnergy(S).E / S.E0 - 1).toFixed(4); out.dEK = +Math.abs((D.gvEnergy(S).E - S.E0) / D.gvEnergy(S).K).toFixed(4); const W = D.gvNew(7, 3); for (let i = 0; i < W.n; i++){ W.vx[i] *= 3; W.vy[i] *= 3; W.vz[i] *= 3; } while (W.t < 30) D.gvStep(W, D.gvH(W)); out.warm30 = +D.gjClumped(W).toFixed(2); return out; }); - const ok = gj.kind === 'jeans' && gj.c0 < 0.05 && gj.c30 > 0.2 && gj.warm > 3 && gj.dE < 0.2 && gj.warm30 < 0.1; // (the mesh's energy drifts 6–14% as clumps reach a cell: Dec 1) + const ok = gj.kind === 'jeans' && gj.c0 < 0.05 && gj.c30 > 0.2 && gj.warm > 3 && gj.dE < 0.1 && gj.dEK < 0.01 && gj.warm30 < 0.1; // (the gas starts with next to no energy of position, so the drift is also read against the warmed gas's motion: Dec 1) if (!ok) failures.push('[gravity jeans] ' + JSON.stringify(gj)); - console.log(`${ok ? 'ok ' : 'FAIL'} gravity lab, clumping: ${gj.c0} in clumps at the start, ${gj.c30} after 30 s, ${gj.warm}× as warm, energy kept to ${gj.dE}; three times as warm (Jeans length past the box) ${gj.warm30}`); + console.log(`${ok ? 'ok ' : 'FAIL'} gravity lab, clumping: ${gj.c0} in clumps at the start, ${gj.c30} after 30 s, ${gj.warm}× as warm, energy kept to ${gj.dE} of the start's, ${gj.dEK} of the motion's at 30 s; three times as warm (Jeans length past the box) ${gj.warm30}`); } // (Nov 30: "Real work presets"): each real system's bodies, given only the outermost one's period, go round in their real periods (to 1%), @@ -2027,13 +2027,17 @@ const game = { title: 'Words', size: l => 5 + Math.ceil(l / 2), const S = D.gvNew(3, 4); while (S.t < 4) D.gvStep(S, D.gvH(S)); D.gvAccel(S); const A = [Array.from(S.ax), Array.from(S.ay), Array.from(S.az)]; S.fine = true; D.gvAccel(S); let e = 0, m = 0; for (let i = 0; i < S.n; i++){ e += (A[0][i] - S.ax[i]) ** 2 + (A[1][i] - S.ay[i]) ** 2 + (A[2][i] - S.az[i]) ** 2; m += S.ax[i] ** 2 + S.ay[i] ** 2 + S.az[i] ** 2; } out.n = S.n; out.tree = +Math.sqrt(e / m).toFixed(4); - const P = D.gvNew(7, 1), n = P.n; for (let i = 0; i < n; i++){ P.m[i] = 0; P.x[i] = 0.13 + (i % 5) * 0.5 + 0.5; P.y[i] = 0.07; P.z[i] = -0.05; } P.m[0] = 1; P.x[0] = 0.13; D.gvAccel(P); - out.mesh = [1, 2, 3].map(k => +(-P.ax[k] * ((P.x[k] - 0.13) ** 2)).toFixed(3)); + const P = D.gvNew(7, 1), n = P.n; for (let i = 0; i < n; i++){ P.m[i] = 0; P.x[i] = 0.13 + [0.15, 0.4, 1, 1.5, 2][i % 5]; P.y[i] = 0.07; P.z[i] = -0.05; } P.m[0] = 1; P.x[0] = 0.13; D.gvAccel(P); + out.mesh = [0, 1, 2, 3, 4].map(k => { const r = P.x[k + 5] - 0.13; return +(-P.ax[k + 5] * (r * r + P.eps * P.eps) ** 1.5 / r).toFixed(3); }); out.pool = D.LABW.W.n; + // (A PIXEL'S WORTH, Dec 1: a far board's bodies sharing a pixel drawn as one, as large as their areas added; above 200 px every body its own) + { const C = D.gvNew(3, 5); while (C.t < 8) D.gvStep(C, D.gvH(C)); const L = D.gvItems(C), a60 = D.labThin(L, 60), a300 = D.labThin(L, 300); + const area = A => A.filter(i => i.kind === 'gvDot').reduce((s, i) => s + i.scale * i.scale, 0); + out.thin = { all: L.length, at60: a60.length, at300: a300.length, area: +(area(a60) / area(L)).toFixed(4), cap: window.getFieldApp().itemCaps('gvDot') }; } return out; }); - const ok = bh.n === 750 && bh.tree < 0.03 && bh.mesh.every(v => Math.abs(v - 1) < 0.1) /* (the wrapping box's copies pull back more the farther out: 0.934 at 2) */ && bh.pool >= 1; + const ok = bh.n === 750 && bh.tree < 0.03 && bh.mesh.slice(0, 3).every(v => Math.abs(v - 1) < 0.07) && bh.mesh.every(v => Math.abs(v - 1) < 0.1) /* (under a cell, 0.25, as well as past it; the wrapping box's copies pull back more the farther out) */ && bh.pool >= 1 && bh.thin.at60 < 0.8 * bh.thin.all && bh.thin.at300 === bh.thin.all && Math.abs(bh.thin.area - 1) < 1e-6 && bh.thin.cap > 48000; if (!ok) failures.push('[gravity tree/mesh] ' + JSON.stringify(bh)); - 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 mesh's pull × r² of one mass at 1, 1.5 and 2: ${bh.mesh}; ${bh.pool} lab worker(s)`); + 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`); } } catch (e){