@jossuealcala/madre 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.en.md +20 -1
  2. package/CHANGELOG.md +20 -1
  3. package/TRADEMARKS.md +6 -2
  4. package/bin/madre.mjs +4 -2
  5. package/docs/REFERENCE.md +3 -3
  6. package/docs/SDK.md +28 -1
  7. package/docs/en/REFERENCE.md +2 -2
  8. package/docs/en/SDK.md +26 -0
  9. package/docs/sdk/hello-module.mjs +38 -3
  10. package/habilidades/explicamelo-facil/HABILIDAD.md +19 -0
  11. package/habilidades/hojas-de-calculo/HABILIDAD.md +18 -0
  12. package/habilidades/mensajes-a-clientes/HABILIDAD.md +19 -0
  13. package/habilidades/publicaciones-para-redes/HABILIDAD.md +19 -0
  14. package/habilidades/resumen-y-pendientes/HABILIDAD.md +18 -0
  15. package/habilidades/tu-pagina-paso-a-paso/HABILIDAD.md +19 -0
  16. package/package.json +4 -3
  17. package/public/activity.js +57 -22
  18. package/public/app.js +3998 -762
  19. package/public/assets/brand/OFL-SpaceGrotesk.txt +93 -0
  20. package/public/assets/brand/SpaceGrotesk-latin-ext.woff2 +0 -0
  21. package/public/assets/brand/SpaceGrotesk-latin.woff2 +0 -0
  22. package/public/assets/brand/madre-app-180.png +0 -0
  23. package/public/assets/brand/madre-app-192.png +0 -0
  24. package/public/assets/brand/madre-app-512.png +0 -0
  25. package/public/assets/brand/madre-app.svg +1 -1
  26. package/public/assets/brand/madre-favicon.svg +1 -1
  27. package/public/attribution.js +28 -27
  28. package/public/auto-open.js +102 -0
  29. package/public/brands.js +9 -6
  30. package/public/changes.js +63 -0
  31. package/public/en.js +1085 -101
  32. package/public/es.js +2395 -1688
  33. package/public/i18n.js +11 -0
  34. package/public/index.html +28 -27
  35. package/public/loader.js +322 -117
  36. package/public/macroverso.js +33 -350
  37. package/public/manual-content.js +37 -7
  38. package/public/manual.js +21 -6
  39. package/public/market-view.js +212 -105
  40. package/public/market.js +10 -2
  41. package/public/mcp-catalog.js +7 -2
  42. package/public/missions.js +169 -0
  43. package/public/news-scenes.js +110 -3
  44. package/public/nostromo-engine.js +935 -654
  45. package/public/notices.js +14 -2
  46. package/public/notifications.js +119 -0
  47. package/public/provider-marks.js +170 -0
  48. package/public/provider-pick.js +147 -0
  49. package/public/resay.js +1 -0
  50. package/public/review-ask.js +16 -13
  51. package/public/routing.js +29 -3
  52. package/public/salas-mac.css +257 -40
  53. package/public/salas-mac.html +5 -5
  54. package/public/salas-mac.js +376 -97
  55. package/public/salas.css +2 -2
  56. package/public/salas.html +2 -2
  57. package/public/salas.js +1 -1
  58. package/public/starters.js +128 -0
  59. package/public/styles.css +2656 -336
  60. package/public/subscription.js +303 -0
  61. package/public/terms-field.js +170 -0
  62. package/public/terms.js +117 -19
  63. package/public/tips.js +41 -7
  64. package/public/tour-chapters.js +35 -35
  65. package/public/tour.js +333 -43
  66. package/public/troubleshooting.js +100 -7
  67. package/public/welcome-scene.js +117 -29
  68. package/public/welcome.js +364 -60
  69. package/src/adapters/claude.mjs +2 -1
  70. package/src/adapters/codex.mjs +2 -1
  71. package/src/adapters/cursor.mjs +9 -6
  72. package/src/adapters/gemini.mjs +4 -0
  73. package/src/adapters/grok.mjs +6 -4
  74. package/src/adapters/madre.mjs +71 -23
  75. package/src/adapters/opencode.mjs +15 -2
  76. package/src/adapters/steps.mjs +176 -0
  77. package/src/app-invite.mjs +90 -0
  78. package/src/billing-key.mjs +8 -0
  79. package/src/billing.mjs +317 -0
  80. package/src/bridge/policy.mjs +1 -1
  81. package/src/capabilities.mjs +17 -11
  82. package/src/chats.mjs +44 -2
  83. package/src/checkpoint.mjs +5 -1
  84. package/src/commands.mjs +5 -2
  85. package/src/directives.mjs +1 -0
  86. package/src/event-store.mjs +15 -0
  87. package/src/extensions.mjs +5 -1
  88. package/src/ficha.mjs +16 -0
  89. package/src/image-studio.mjs +13 -3
  90. package/src/install-metrics.mjs +9 -3
  91. package/src/lease.mjs +1 -1
  92. package/src/looks.mjs +4 -1
  93. package/src/mcp/image-server.mjs +59 -90
  94. package/src/modules/ahp.mjs +2 -1
  95. package/src/modules/github.mjs +6 -2
  96. package/src/modules/image-providers.mjs +281 -0
  97. package/src/modules/image-studio.mjs +100 -19
  98. package/src/modules/index.mjs +7 -1
  99. package/src/modules/intents-observe.mjs +3 -1
  100. package/src/modules/playwright.mjs +33 -4
  101. package/src/modules/reminders.mjs +42 -2
  102. package/src/modules/ripley.mjs +2 -1
  103. package/src/modules/sdk.mjs +6 -1
  104. package/src/opencode-health.mjs +1 -1
  105. package/src/outbound.mjs +80 -6
  106. package/src/quota-sources.mjs +148 -3
  107. package/src/review-ask.mjs +55 -31
  108. package/src/room/changes.mjs +79 -0
  109. package/src/room/economy.mjs +1 -1
  110. package/src/room/guard.mjs +8 -1
  111. package/src/room/prompt.mjs +20 -4
  112. package/src/room.mjs +87 -21
  113. package/src/salas.mjs +30 -3
  114. package/src/server.mjs +545 -59
  115. package/src/setup.mjs +1 -1
  116. package/src/skills.mjs +10 -0
  117. package/src/terms.mjs +23 -5
  118. package/src/tour.mjs +18 -3
  119. package/src/updates.mjs +47 -4
  120. package/src/web-preview.mjs +181 -0
  121. package/src/whats-new.mjs +76 -4
@@ -15,11 +15,10 @@
15
15
  // the room's language, how much of the canvas the open card covers, what to shake when CODE000
16
16
  // lands — are hooks on the scene (`words`, `covered`, `onClang`), and each has a default.
17
17
 
18
- // Memories burn as stars burn, and a star's colour is its class. A decision is a yellow dwarf,
19
- // the steady kind a system is built around. A fact is a white dwarf: cold, dense, settled. A
20
- // preference is a green dwarf, personal and very long lived. A question is a blue dwarf, the
21
- // hottest thing in the sky and the least settled. One palette for the room, the Macroverso and
22
- // the stylesheet (`--mem-*`): a test keeps them the same.
18
+ // Each kind of memory has its colour: a decision yellow, a fact white, a preference green, a
19
+ // question blue, a doubtful memory violet. The wires, the pulses and every chip outside the map wear
20
+ // it; on the map itself each kind is a planet that looks like it (PLANETS, below). One palette for the
21
+ // room, the Macroverso and the stylesheet (`--mem-*`): a test keeps them the same.
23
22
  export const MEMORY_COLORS = { decision: '#ffdc3c', fact: '#dfeeff', preference: '#5cf07a', question: '#3dc6ff', aberration: '#b14cff' };
24
23
  // What a zone changes on the map is whether the star is lit: only what still travels into turns
25
24
  // burns. The rule is the archive's (`travels()` in src/memory.mjs); this is the client's copy.
@@ -280,203 +279,59 @@ const CIRCLE_STEPS = 44;
280
279
  const CIRCLE_COS = Array.from({ length: CIRCLE_STEPS + 1 }, (_, k) => Math.cos((k / CIRCLE_STEPS) * Math.PI * 2));
281
280
  const CIRCLE_SIN = Array.from({ length: CIRCLE_STEPS + 1 }, (_, k) => Math.sin((k / CIRCLE_STEPS) * Math.PI * 2));
282
281
 
283
- // ---- The skin of a dwarf.
284
- // A star of any class has the same boiling surface; what changes is the colour it boils in. One
285
- // strip is built per class, the first time that class is asked for, and every memory of that
286
- // class wears it. The strip repeats left to right, so a body can turn inside it without a seam.
287
- const dwarfSkins = new Map();
288
- // A dwarf's face is laid on in columns across its width, each as wide as a sphere is at that
289
- // longitude: the sine of evenly spaced longitudes from one limb to the other.
290
- const SKIN_COLUMNS = 8;
291
- const SKIN_EDGES = Array.from({ length: SKIN_COLUMNS + 1 }, (_, k) => Math.sin(-Math.PI / 2 + (k / SKIN_COLUMNS) * Math.PI));
292
- export function dwarfTexture(hex) {
293
- if (dwarfSkins.has(hex)) return dwarfSkins.get(hex);
294
- let skin = null;
295
- try {
296
- const base = [1, 3, 5].map((at) => Number.parseInt(String(hex).slice(at, at + 2), 16));
297
- if (base.some((value) => !Number.isFinite(value))) throw new Error('not a colour');
298
- const shade = (amount, alpha) => `rgba(${base.map((value) => Math.round(Math.min(255, value * amount))).join(', ')}, ${alpha})`;
299
- const white = (amount, alpha) => `rgba(${base.map((value) => Math.round(value + (255 - value) * amount)).join(', ')}, ${alpha})`;
300
- const width = 320;
301
- const height = 160;
302
- const canvas = document.createElement('canvas');
303
- canvas.width = width * 2;
304
- canvas.height = height;
305
- const paint = canvas.getContext('2d');
306
- if (!paint) throw new Error('no context');
307
- // The ground of the face, in the star's own colour. A dwarf is bright from edge to edge, so
308
- // this is the colour at rest rather than a dark floor: the mottling reads against it both
309
- // ways, darker where the gas is cooler and white where it is alight.
310
- paint.fillStyle = shade(0.46, 1);
311
- paint.fillRect(0, 0, width * 2, height);
312
- const cell = (x, y, size, heat) => {
313
- for (const at of [x - width, x, x + width]) {
314
- const glow = paint.createRadialGradient(at, y, 0, at, y, size);
315
- if (heat > 0.88) {
316
- // The few points that are truly alight, which is what the eye finds first.
317
- glow.addColorStop(0, white(0.85, 0.95));
318
- glow.addColorStop(0.4, white(0.35, 0.5));
319
- } else if (heat > 0.52) {
320
- glow.addColorStop(0, white(0.2 + heat * 0.3, 0.45 + heat * 0.35));
321
- glow.addColorStop(0.5, shade(1.05, 0.24));
322
- } else {
323
- glow.addColorStop(0, shade(0.2 + heat * 0.5, 0.5));
324
- glow.addColorStop(0.5, shade(0.22, 0.24));
325
- }
326
- glow.addColorStop(1, shade(0.5, 0));
327
- paint.fillStyle = glow;
328
- paint.beginPath(); paint.arc(at, y, size, 0, Math.PI * 2); paint.fill();
329
- }
330
- };
331
- for (let i = 0; i < 420; i += 1) cell(Math.random() * width, Math.random() * height, 7 + Math.random() * 15, Math.random() * 0.82);
332
- for (let i = 0; i < 1100; i += 1) cell(Math.random() * width, Math.random() * height, 1.8 + Math.random() * 4.5, Math.random());
333
- skin = canvas;
334
- } catch {
335
- skin = null; // no canvas to build in: the star keeps its gradient and loses its grain
336
- }
337
- dwarfSkins.set(hex, skin);
338
- return skin;
339
- }
340
-
341
- // ---- The legend's stars (moved here from app.js on 2026-10-10, so the Project map draws the same
342
- // ones as the Memory map).
343
- // A real dwarf, small enough to sit in a chip: the same ground, the same boiling face and the
344
- // same limb the ones in the constellation wear, so the legend shows the thing and not a swatch.
345
- export function dwarfChip(hex, px) {
346
- const canvas = document.createElement('canvas');
347
- const dpr = Math.min(3, window.devicePixelRatio || 1);
348
- canvas.width = Math.round(px * dpr);
349
- canvas.height = Math.round(px * dpr);
350
- canvas.style.width = `${px}px`;
351
- canvas.style.height = `${px}px`;
352
- const paint = canvas.getContext('2d');
353
- if (!paint) return canvas;
354
- paint.scale(dpr, dpr);
355
- const r = px / 2;
356
- paint.save();
357
- paint.beginPath(); paint.arc(r, r, r, 0, Math.PI * 2); paint.closePath();
358
- const ground = paint.createRadialGradient(r * 0.72, r * 0.72, r * 0.04, r, r, r * 1.1);
359
- ground.addColorStop(0, hexMix(hex, '#ffffff', 0.75));
360
- ground.addColorStop(0.42, hex);
361
- ground.addColorStop(1, hexMix(hex, '#000000', 0.62));
362
- paint.fillStyle = ground;
363
- paint.fill();
364
- paint.clip();
365
- const skin = dwarfTexture(hex);
366
- if (skin) {
367
- paint.globalAlpha = 0.72;
368
- paint.drawImage(skin, 0, 0, skin.width * 0.28, skin.height, -r * 0.08, -r * 0.08, px * 1.08, px * 1.08);
369
- paint.globalAlpha = 1;
370
- }
371
- const limb = paint.createRadialGradient(r, r, r * 0.3, r, r, r);
372
- limb.addColorStop(0, 'rgba(0, 0, 0, 0)');
373
- limb.addColorStop(0.78, 'rgba(0, 0, 0, .18)');
374
- limb.addColorStop(1, 'rgba(0, 0, 0, .6)');
375
- paint.fillStyle = limb;
376
- paint.fillRect(0, 0, px, px);
377
- paint.restore();
378
- return canvas;
379
- }
380
-
381
- // The collapsed body, small enough for a chip: a hole with the ring of what fell into it.
382
- export function collapsedChip(hex, px) {
383
- const canvas = document.createElement('canvas');
384
- const dpr = Math.min(3, window.devicePixelRatio || 1);
385
- canvas.width = Math.round(px * dpr);
386
- canvas.height = Math.round(px * dpr);
387
- canvas.style.width = `${px}px`;
388
- canvas.style.height = `${px}px`;
389
- const paint = canvas.getContext('2d');
390
- if (!paint) return canvas;
391
- paint.scale(dpr, dpr);
392
- const r = px / 2;
393
- // The same thing the constellation draws, small: dust, a round black nothing, a cold rim.
394
- paint.globalCompositeOperation = 'lighter';
395
- for (let i = 0; i < 14; i += 1) {
396
- const speck = VOID_DUST[i * 4];
397
- const at = r * (0.78 + 0.22 * speck.out);
398
- const x = r + Math.cos(speck.angle) * at;
399
- const y = r + Math.sin(speck.angle) * at;
400
- paint.fillStyle = `rgba(${speck.colour}, ${0.8 - 0.4 * speck.out})`;
401
- paint.beginPath(); paint.arc(x, y, 0.55, 0, Math.PI * 2); paint.fill();
402
- }
403
- paint.globalCompositeOperation = 'source-over';
404
- paint.fillStyle = '#000000';
405
- paint.beginPath(); paint.arc(r, r, r * 0.66, 0, Math.PI * 2); paint.fill();
406
- paint.globalCompositeOperation = 'lighter';
407
- paint.strokeStyle = 'rgba(168, 204, 255, .75)';
408
- paint.lineWidth = 0.9;
409
- paint.beginPath(); paint.arc(r, r, r * 0.69, 0.6, 3.5); paint.stroke();
410
- paint.strokeStyle = 'rgba(140, 180, 245, .45)';
411
- paint.beginPath(); paint.arc(r, r, r * 0.74, 3.9, 5.9); paint.stroke();
412
- paint.globalCompositeOperation = 'source-over';
413
- return canvas;
414
- }
415
-
416
- // ---- A dwarf, drawn the way a star looks.
282
+ // ---- The memories are planets (2026-11-15, asked by the author: «planetas en memorias deben verse
283
+ // hiperrealistas, iluminados y sombreados por el sol, … 4 tipos de planetas en colores tipo Mercurio,
284
+ // Urano, Tierra y Marte»).
417
285
  //
418
- // A dwarf makes its own light, so nothing out here lights it and nothing shades it: there is
419
- // no side turned away. What makes it round is what makes the Sun round in a white-light photo.
286
+ // A memory used to be a dwarf star that made its own light. It is a planet now, and a planet gives
287
+ // none: the sun at the centre of the map lights it from where it stands. The side turned to the sun
288
+ // is day; the far side is night, almost black, with only a little light from everything else; the
289
+ // line between them, the terminator, moves as the planet goes round its orbit or as the map is
290
+ // turned, because the direction of the sun is worked out again from where the planet is each time
291
+ // its face is painted.
420
292
  //
421
- // Limb darkening. The disc is brightest in the middle and dims toward the edge, the same all
422
- // the way round: at the limb the eye sees into higher, cooler gas. It dims more in blue than
423
- // in red, so the edge is also warmer than the centre.
424
- // Granulation. The surface is cells: hot plasma rising in bright cores, cooling gas sinking in
425
- // the dark lanes between them. Seen toward the limb the cells foreshorten and the pattern fades.
426
- // Spots. A dark umbra inside a paler penumbra, where the field holds the heat down.
427
- // Faculae. Bright patches around the spots, plain near the limb and nearly lost in the middle.
293
+ // Each kind of memory is one planet, chosen for looking like the colour that kind has always had:
294
+ // a fact is Mercury: grey rock, cratered all over, no air; a few young craters throw bright rays;
295
+ // a decision is Mars: rust and butterscotch, darker basalt plains, a canyon, a white polar cap;
296
+ // a preference is the Earth: oceans, continents, deserts, ice, clouds that drift a little faster
297
+ // than the ground, a blue atmosphere, and the sun's glint on the water;
298
+ // a question is Uranus: pale cyan and smooth, with bands too faint to name and a haze at its edge.
299
+ // All of it is grown here from noise: no picture of a planet is used and nothing is downloaded.
428
300
  //
429
- // Each class wears these in its own proportion: a white dwarf is smooth and white-hot, a yellow
430
- // one is a sun with granules and spots. The surface is a map of the whole body in latitude and
431
- // longitude, built once per class from noise sampled on the sphere itself, so it has no seam and
432
- // nothing stretches at the poles; turning the body is sliding along it. How hard a dwarf burns
433
- // is how much the room has made of it, as before.
301
+ // What makes them read as real is how the light falls. The rocky two are lit as the Moon is (a
302
+ // blend of Lommel–Seeliger and Lambert): even across the day side, then falling off hard at the
303
+ // terminator, their relief raised by the light that grazes it. The two with air are lit softly,
304
+ // darker toward the limb, and wear a halo of atmosphere on the side the sun is on, all the way
305
+ // round when the sun is behind them. The colours are lit in linear light and brought back for the
306
+ // screen, so the terminator fades the way it does in a photograph instead of as a grey band.
434
307
  //
435
- // The geometry of a disc of a given size is worked out once and kept. A body is painted again
436
- // only when it has turned or changed enough to show.
308
+ // `base` is the planet's colour at a glance, for wherever there is no face to paint yet; `bump` how
309
+ // far its relief tilts the light; `wrap` how far its air carries light past the terminator; `limb`
310
+ // how much it darkens toward the edge; `air` the colour of its atmosphere and `airGlow` how bright
311
+ // its halo is, `thickness` how far it reaches past the limb; `face` the turn the legend shows it at.
312
+ export const PLANETS = {
313
+ fact: { name: 'mercury', base: '#8f8a84', rocky: true, bump: 0.075, wrap: 0, limb: 0, air: null, airGlow: 0, thickness: 0, face: 0.6 },
314
+ decision: { name: 'mars', base: '#b8683c', rocky: true, bump: 0.035, wrap: 0, limb: 0, air: [1, 0.72, 0.52], airGlow: 0.3, thickness: 0.022, face: 2.1 },
315
+ preference: { name: 'earth', base: '#2f5f8f', rocky: false, bump: 0.03, wrap: 0.05, limb: 0.12, air: [0.36, 0.6, 1], airGlow: 0.95, thickness: 0.035, ocean: true, clouds: true, face: 4.4 },
316
+ question: { name: 'uranus', base: '#a2d6de', rocky: false, bump: 0, wrap: 0.07, limb: 0.42, air: [0.66, 0.9, 1], airGlow: 0.55, thickness: 0.032, face: 0 },
317
+ };
318
+ // A kind the map does not know is drawn as a fact, as its colour always was.
319
+ export const planetOf = (kind) => (PLANETS[kind] ? kind : 'fact');
320
+ // How far past its disc a planet's painted face reaches, for the halo of its air.
321
+ const PLANET_HALO = 1.16;
322
+ // The sun at the centre is a little warm of white, and so is the light it gives.
323
+ const SUN_LIGHT = [1, 0.95, 0.88];
324
+ // What reaches the night side from everything that is not the sun: almost nothing.
325
+ const PLANET_AMBIENT = 0.04;
326
+
327
+ // The surface of each planet is a map of the whole body in latitude and longitude, built once per
328
+ // kind from noise sampled on the sphere itself, so it has no seam and nothing stretches at the
329
+ // poles; turning the body is sliding along it.
437
330
  const ALBEDO_W = 256;
438
331
  const ALBEDO_H = 128;
439
- // How much each channel dims at the limb, red to blue: the blue dims most.
440
- const LIMB_DARKENING = [0.68, 0.8, 0.9];
441
- // What each class of dwarf is made of. `granules` is how strongly the cells show, `spots` how
442
- // many of them are marked, `faculae` how bright the patches around them are, `white` how far the
443
- // centre runs toward white, `power` how much light it gives for its size: a white dwarf is the
444
- // smallest and the most intense. A class not named here is drawn as a sun.
445
- const STAR_TRAITS = {
446
- decision: { granules: 1, spots: 1, faculae: 1, white: 0.5, power: 1 },
447
- fact: { granules: 0.3, spots: 0, faculae: 0.35, white: 0.9, power: 1.35 },
448
- preference: { granules: 0.9, spots: 0.7, faculae: 0.9, white: 0.45, power: 1 },
449
- question: { granules: 0.7, spots: 0.4, faculae: 0.7, white: 0.65, power: 1.15 },
450
- };
451
- const SUN_TRAITS = { granules: 0.8, spots: 0.6, faculae: 0.8, white: 0.5, power: 1 };
452
- // And what a memory's standing does to that surface. A dwarf you confirmed is clean; one nobody
453
- // has judged carries its class's spots; one held as false is blotched, the spots spreading as
454
- // `reach` drops; one put out of circulation is the worst of all. `faculae` scales the bright
455
- // patches. A dwarf the archive has never once carried is cooling: its granules barely move, it
456
- // gives less light (`glow`) and its middle is no longer white-hot (`white`).
457
- const SURFACE_BY_ZONE = {
458
- bridge: { spots: 0, reach: 0.77, faculae: 1.3 },
459
- hold: { spots: 1, reach: 0.77, faculae: 1 },
460
- medbay: { spots: 1, reach: 0.67, faculae: 0.55, sick: true },
461
- jettisoned: { spots: 1, reach: 0.62, faculae: 0.3, sick: true },
462
- };
463
- const COLD_GRANULES = 0.3;
464
- const COLD_GLOW = 0.55;
465
- const COLD_WHITE = 0.2;
466
- function surfaceOf(memory, traits = SUN_TRAITS, cold = false) {
467
- const zone = SURFACE_BY_ZONE[memory?.zone ?? 'hold'] ?? SURFACE_BY_ZONE.hold;
468
- return {
469
- spots: zone.sick ? 1 : traits.spots * zone.spots,
470
- reach: zone.reach,
471
- faculae: traits.faculae * zone.faculae,
472
- granules: traits.granules * (cold ? COLD_GRANULES : 1),
473
- glow: cold ? COLD_GLOW : 1,
474
- white: cold ? COLD_WHITE : 1,
475
- };
476
- }
477
- const dwarfAlbedos = new Map();
478
332
  const sphereTables = new Map();
479
333
 
334
+
480
335
  // Gradient noise, the improved kind: continuous in every direction, with no grid showing
481
336
  // through it the way value noise shows its cells. The permutation is fixed, so every room grows
482
337
  // the same surfaces.
@@ -490,7 +345,7 @@ const NOISE_PERM = (() => {
490
345
  }
491
346
  return Uint8Array.from([...order, ...order]);
492
347
  })();
493
- function gradientNoise(x, y, z) {
348
+ export function gradientNoise(x, y, z) {
494
349
  const P = NOISE_PERM;
495
350
  const X = Math.floor(x) & 255, Y = Math.floor(y) & 255, Z = Math.floor(z) & 255;
496
351
  x -= Math.floor(x); y -= Math.floor(y); z -= Math.floor(z);
@@ -509,7 +364,7 @@ function gradientNoise(x, y, z) {
509
364
  lerp(v, lerp(u, grad(P[AA + 1], x, y, z - 1), grad(P[BA + 1], x - 1, y, z - 1)), lerp(u, grad(P[AB + 1], x, y - 1, z - 1), grad(P[BB + 1], x - 1, y - 1, z - 1))));
510
365
  }
511
366
  // Octaves of it, folded into 0..1.
512
- function fractalNoise(x, y, z, octaves) {
367
+ export function fractalNoise(x, y, z, octaves) {
513
368
  let sum = 0, amp = 0.5, freq = 1, norm = 0;
514
369
  for (let i = 0; i < octaves; i += 1) { sum += amp * gradientNoise(x * freq, y * freq, z * freq); norm += amp; amp *= 0.5; freq *= 2.03; }
515
370
  return 0.5 + 0.5 * Math.max(-1, Math.min(1, (sum / norm) * 1.6));
@@ -517,7 +372,7 @@ function fractalNoise(x, y, z, octaves) {
517
372
  // Cellular noise: the distance to the nearest and the second nearest of a scatter of points,
518
373
  // one jittered into each unit cell. Where the two are nearly equal is the border between two
519
374
  // cells, which is exactly the shape of a granule's dark lane.
520
- function cellNoise(x, y, z) {
375
+ export function cellNoise(x, y, z) {
521
376
  const P = NOISE_PERM;
522
377
  const xi = Math.floor(x), yi = Math.floor(y), zi = Math.floor(z);
523
378
  let near = 9, next = 9;
@@ -534,46 +389,311 @@ function cellNoise(x, y, z) {
534
389
 
535
390
  const smooth = (a, b, x) => { const t = Math.min(1, Math.max(0, (x - a) / (b - a))); return t * t * (3 - 2 * t); };
536
391
 
537
- // The whole surface of one class: how bright the granulation is at each texel, and how strong
538
- // the magnetic field is there. Spots and faculae are read from the field when a dwarf is
539
- // painted, so how many a dwarf shows can follow the memory's standing instead of being baked in.
540
- // Each class has a surface of its own. Built a band of rows at a time when asked to be (`rows`),
541
- // so the work can be spread over frames; the map is handed out only once it is whole.
542
- function dwarfAlbedo(kind, rows = ALBEDO_H) {
543
- let build = dwarfAlbedos.get(kind);
392
+ const sunClamp = (value, low, high) => Math.min(high, Math.max(low, value));
393
+ // ---- The sun at the centre of the projects (2026-11-10, asked by the author: «the sun does not feel
394
+ // like a real sun»). The Coordinator in the planets view is a star now, and so is the centre of every project's map (2026-11-10: «the sun in the projects does not look like the Coordinator's»), drawn as the Sun is seen in a
395
+ // white-light photograph, from the same noise the memories' planets are made of (this file):
396
+ // granulation — bright cells of rising gas and dark lanes between them, over a slow unevenness;
397
+ // spots — a dark umbra in a paler penumbra, a few, drifting with the turn;
398
+ // limb darkening — brightest in the middle, dimmer and warmer toward the edge, more in blue than
399
+ // in red, which is what makes a disc of light read as a ball;
400
+ // round it — a tight bright skin at the limb and a wide warm glow, no rays.
401
+ // The surface is a map of the whole body in latitude and longitude, built once; turning is sliding
402
+ // along it. Painted at `side` pixels (SUN_SIDE in Home, more on a map seen up close) and scaled.
403
+ const SUN_SIDE = 192;
404
+ const SUN_W = 256;
405
+ const SUN_H = 128;
406
+ // How much each channel dims at the limb, red to blue.
407
+ const SUN_LIMB = [0.42, 0.62, 0.86];
408
+ // The photosphere's own colour, a little warm of white.
409
+ const SUN_TONE = [255, 236, 196];
410
+ export function sunOrb({ side = SUN_SIDE } = {}) {
411
+ // The surface keeps about two of its texels to each pixel across the face, whatever the size.
412
+ const W = Math.min(1024, Math.max(SUN_W, side * 2));
413
+ const H = W / 2;
414
+ const map = new Float32Array(W * H);
415
+ // A few spots, each a latitude, a longitude and a size, in the bands spots keep to.
416
+ const spots = [[0.28, 0.6, 0.07], [0.22, 0.9, 0.045], [-0.3, 2.4, 0.06], [-0.24, 2.62, 0.035], [0.18, 4.1, 0.05], [-0.2, 5.3, 0.04]];
417
+ for (let row = 0; row < H; row += 1) {
418
+ const lat = ((row + 0.5) / H - 0.5) * Math.PI;
419
+ const cl = Math.cos(lat), sl = Math.sin(lat);
420
+ for (let col = 0; col < W; col += 1) {
421
+ const lon = ((col + 0.5) / W) * Math.PI * 2;
422
+ const x = cl * Math.cos(lon), y = sl, z = cl * Math.sin(lon);
423
+ const [near, next] = cellNoise(x * 14 + 3, y * 14, z * 14);
424
+ const lanes = smooth(0.02, 0.22, next - near);
425
+ const drift = fractalNoise(x * 2.4 + 9, y * 2.4, z * 2.4, 4);
426
+ let bright = 0.7 + 0.28 * lanes + 0.2 * (drift - 0.5);
427
+ for (const [sLat, sLon, size] of spots) {
428
+ const d = Math.acos(sunClamp(Math.sin(sLat) * sl + Math.cos(sLat) * cl * Math.cos(lon - sLon), -1, 1));
429
+ if (d < size * 1.9) bright *= 0.45 + 0.55 * smooth(size * 0.55, size * 1.9, d) + (d < size * 0.55 ? -0.25 : 0);
430
+ }
431
+ map[row * W + col] = sunClamp(bright, 0.05, 1.1);
432
+ }
433
+ }
434
+ // Where each pixel of the face lands on the surface, worked out once: turning is only adding to
435
+ // its longitude, so a bigger sun costs a lookup per pixel and no trigonometry.
436
+ const half = side / 2;
437
+ const cells = [];
438
+ for (let py = 0; py < side; py += 1) {
439
+ const ny = (py + 0.5 - half) / half;
440
+ for (let px = 0; px < side; px += 1) {
441
+ const nx = (px + 0.5 - half) / half;
442
+ const rr = nx * nx + ny * ny;
443
+ if (rr > 1) continue;
444
+ const mu = Math.sqrt(1 - rr);
445
+ // A slight lean, so the spots' bands are not a flat line across the face.
446
+ const lat = Math.asin(sunClamp(-ny * 0.96 + mu * 0.28, -1, 1));
447
+ const v = sunClamp(lat / Math.PI + 0.5, 0, 0.999);
448
+ cells.push((py * side + px) * 4, Math.floor(v * H) * W, Math.atan2(nx, mu) / (Math.PI * 2), mu, Math.min(1, (1 - Math.sqrt(rr)) * half * 0.9));
449
+ }
450
+ }
451
+ const canvas = document.createElement('canvas');
452
+ canvas.width = side;
453
+ canvas.height = side;
454
+ const pen = canvas.getContext('2d');
455
+ const image = pen.createImageData(side, side);
456
+ const sun = { canvas, paintedAt: -1 };
457
+ // `turn` in radians; `life` dims it while the Coordinator's room sleeps.
458
+ sun.paint = (turn, life = 1) => {
459
+ const data = image.data;
460
+ const shift = turn / (Math.PI * 2);
461
+ for (let i = 0; i < cells.length; i += 5) {
462
+ const k = cells[i], mu = cells[i + 3];
463
+ const u = ((cells[i + 2] + shift) % 1 + 1) % 1;
464
+ const g = map[cells[i + 1] + Math.floor(u * W)];
465
+ // The pattern fades toward the limb, where the cells foreshorten.
466
+ const grain = 1 + (g - 0.86) * (0.35 + 0.65 * mu);
467
+ for (let c = 0; c < 3; c += 1) {
468
+ const limb = 1 - SUN_LIMB[c] * (1 - mu);
469
+ data[k + c] = sunClamp(SUN_TONE[c] * limb * grain * life * 1.04, 0, 255);
470
+ }
471
+ data[k + 3] = 255 * cells[i + 4];
472
+ }
473
+ pen.putImageData(image, 0, 0);
474
+ };
475
+ return sun;
476
+ }
477
+
478
+ // The sun where it sits: the warm light it gives, wide and breathing a little, then its body, then a
479
+ // tight bright skin gripping the limb. The same in Home's planets view and at the centre of a map.
480
+ export function drawSun(ctx, x, y, r, sun, { life = 1, beat = 0, lit = 0 } = {}) {
481
+ ctx.globalCompositeOperation = 'lighter';
482
+ const reach = r * (3.4 + 0.15 * beat);
483
+ const glow = ctx.createRadialGradient(x, y, r * 0.9, x, y, reach);
484
+ glow.addColorStop(0, `rgba(255, 196, 110, ${0.42 * life})`);
485
+ glow.addColorStop(0.18, `rgba(255, 150, 60, ${0.2 * life})`);
486
+ glow.addColorStop(0.5, `rgba(240, 96, 30, ${0.07 * life})`);
487
+ glow.addColorStop(1, 'rgba(200, 60, 20, 0)');
488
+ ctx.fillStyle = glow;
489
+ ctx.beginPath(); ctx.arc(x, y, reach, 0, Math.PI * 2); ctx.fill();
490
+ ctx.globalCompositeOperation = 'source-over';
491
+ ctx.drawImage(sun.canvas, x - r, y - r, r * 2, r * 2);
492
+ ctx.globalCompositeOperation = 'lighter';
493
+ const skin = ctx.createRadialGradient(x, y, r * 0.94, x, y, r * 1.18);
494
+ skin.addColorStop(0, `rgba(255, 226, 160, ${Math.min(1, (0.5 + 0.4 * lit) * life)})`);
495
+ skin.addColorStop(0.35, `rgba(255, 170, 80, ${Math.min(1, (0.22 + 0.25 * lit) * life)})`);
496
+ skin.addColorStop(1, 'rgba(255, 120, 40, 0)');
497
+ ctx.fillStyle = skin;
498
+ ctx.beginPath(); ctx.arc(x, y, r * 1.18, 0, Math.PI * 2); ctx.fill();
499
+ ctx.globalCompositeOperation = 'source-over';
500
+ }
501
+
502
+ // ---- What each planet is made of, at one point of its sphere.
503
+ //
504
+ // Craters: one candidate in each cell of a lattice laid through the body, kept only where the cell's
505
+ // hash says so, each with a size of its own (many small ones, few large). Each is a bowl, a raised
506
+ // rim and a blanket of thrown-out rock round it; a young one, now and then, has a bright floor and
507
+ // rays streaking out from it. Returns the height and the brightness of the rays.
508
+ const CRATER = new Float32Array(2);
509
+ function craterField(x, y, z, density) {
510
+ const P = NOISE_PERM;
511
+ const xi = Math.floor(x), yi = Math.floor(y), zi = Math.floor(z);
512
+ const keep = density * 255;
513
+ let height = 0;
514
+ let rays = 0;
515
+ for (let dx = -1; dx <= 1; dx += 1) for (let dy = -1; dy <= 1; dy += 1) for (let dz = -1; dz <= 1; dz += 1) {
516
+ const h = P[(P[(P[(xi + dx) & 255] + ((yi + dy) & 255)) & 255] + ((zi + dz) & 255)) & 255];
517
+ if (P[(h + 31) & 255] > keep) continue;
518
+ const ox = x - (xi + dx + P[h] / 255);
519
+ const oy = y - (yi + dy + P[(h + 85) & 255] / 255);
520
+ const oz = z - (zi + dz + P[(h + 170) & 255] / 255);
521
+ const size = 0.14 + 0.36 * (P[(h + 113) & 255] / 255) ** 2;
522
+ const far = ox * ox + oy * oy + oz * oz;
523
+ if (far > size * size * 6.25) continue;
524
+ const reach = Math.sqrt(far);
525
+ const d = reach / size;
526
+ height += (d < 1 ? -(1 - d * d) * 0.9 : 0) + 0.3 * Math.exp(-(((d - 1) / 0.17) ** 2)) + 0.1 * Math.exp(-Math.abs(d - 1) / 0.45);
527
+ if (P[(h + 57) & 255] < 34) {
528
+ const inv = 1 / (reach || 1);
529
+ const streak = gradientNoise(ox * inv * 7 + h * 0.37, oy * inv * 7, oz * inv * 7);
530
+ rays += (d < 1 ? 0.4 : 0) + Math.max(0, streak) * 1.6 * smooth(0.85, 1.1, d) * Math.exp(-Math.max(0, d - 1) / 0.6);
531
+ }
532
+ }
533
+ CRATER[0] = height;
534
+ CRATER[1] = rays;
535
+ return CRATER;
536
+ }
537
+
538
+ // One point of a planet: its colour (0..1, as seen), how glossy it is (open water), how much cloud
539
+ // is over it, and its height. `s` is written in place: r, g, b, gloss, cloud, height.
540
+ function planetSurface(kind, x, y, z, s) {
541
+ let r;
542
+ let g;
543
+ let b;
544
+ let gloss = 0;
545
+ let cloud = 0;
546
+ let height = 0;
547
+ if (kind === 'decision') {
548
+ // Mars. Bright dust and dark basalt, the dark lying more in one hemisphere; low old craters; a
549
+ // long canyon near the equator; and the cap of ice at each pole, larger at one.
550
+ const warp = fractalNoise(x * 1.4 + 31, y * 1.4, z * 1.4, 3) - 0.5;
551
+ const basalt = smooth(0.5, 0.68, fractalNoise(x * 1.9 + warp * 1.6, y * 1.9 + 7 + warp, z * 1.9 - warp * 1.6, 5) + 0.09 * smooth(-0.3, 0.5, y));
552
+ const dust = fractalNoise(x * 6 + 3, y * 6, z * 6, 4);
553
+ craterField(x * 4 + 70, y * 4, z * 4, 0.4);
554
+ const big = CRATER[0];
555
+ craterField(x * 10 + 9, y * 10, z * 10, 0.45);
556
+ const small = CRATER[0];
557
+ const canyon = smooth(0.9, 0.975, 1 - Math.abs(gradientNoise(x * 2.4 + 2, y * 13, z * 2.4))) * Math.exp(-((y / 0.16) ** 2)) * smooth(0.1, 0.5, z);
558
+ height = 0.4 * (fractalNoise(x * 2.4 + 50, y * 2.4, z * 2.4, 4) - 0.5) + 0.45 * big + 0.22 * small - 0.7 * canyon;
559
+ const lift = 0.92 + 0.16 * dust;
560
+ const dark = basalt * 0.85 + 0.35 * canyon;
561
+ r = (0.79 + (0.4 - 0.79) * dark) * lift;
562
+ g = (0.46 + (0.25 - 0.46) * dark) * lift;
563
+ b = (0.25 + (0.17 - 0.25) * dark) * lift;
564
+ const edge = 0.035 * gradientNoise(x * 9, y * 9, z * 9);
565
+ const cap = Math.max(smooth(0.885, 0.91, -y + edge), smooth(0.93, 0.95, y + edge));
566
+ r += (0.95 - r) * cap; g += (0.93 - g) * cap; b += (0.9 - b) * cap;
567
+ height += 0.06 * cap;
568
+ } else if (kind === 'preference') {
569
+ // The Earth. Continents out of warped noise, a shallow shelf round them, green where it is wet,
570
+ // sand in the dry belts either side of the tropics, tundra and ice toward the poles; mountains
571
+ // from a ridged noise; clouds in streets along the latitudes, thicker at the equator and in the
572
+ // storm belts, clearer over the deserts.
573
+ const w = fractalNoise(x * 1.3 + 11, y * 1.3, z * 1.3, 3) - 0.5;
574
+ const c = fractalNoise(x * 1.3 + w * 1.3, y * 1.3 + w, z * 1.3 - w * 1.3 + 2, 6);
575
+ const SEA = 0.58; // about a third of the globe is land
576
+ const land = smooth(SEA, SEA + 0.012, c);
577
+ const shelf = smooth(SEA - 0.07, SEA, c) ** 2;
578
+ const ay = Math.abs(y);
579
+ const detail = fractalNoise(x * 12, y * 12, z * 12, 3);
580
+ const moist = fractalNoise(x * 3.1 + 21, y * 3.1, z * 3.1, 4);
581
+ const desert = smooth(0.35, 0.62, Math.exp(-(((ay - 0.4) / 0.17) ** 2)) * 0.9 + (0.5 - moist) * 1.1);
582
+ const relief = smooth(SEA + 0.02, SEA + 0.22, c);
583
+ const ridges = 1 - Math.abs(gradientNoise(x * 9 + 5, y * 9, z * 9));
584
+ const tropic = Math.exp(-((ay / 0.24) ** 2));
585
+ let lr = 0.11 + 0.06 * detail - 0.04 * tropic;
586
+ let lg = 0.22 + 0.07 * detail - 0.05 * tropic;
587
+ let lb = 0.07 + 0.02 * detail - 0.02 * tropic;
588
+ lr += (0.66 * (0.9 + 0.2 * detail) - lr) * desert;
589
+ lg += (0.53 * (0.9 + 0.2 * detail) - lg) * desert;
590
+ lb += (0.34 * (0.9 + 0.2 * detail) - lb) * desert;
591
+ const tundra = smooth(0.6, 0.75, ay);
592
+ lr += (0.36 - lr) * tundra; lg += (0.34 - lg) * tundra; lb += (0.28 - lb) * tundra;
593
+ const peaks = 0.45 * relief * ridges;
594
+ lr += (0.44 - lr) * peaks; lg += (0.38 - lg) * peaks; lb += (0.32 - lb) * peaks;
595
+ const wr = 0.012 + (0.035 - 0.012) * shelf;
596
+ const wg = 0.045 + (0.15 - 0.045) * shelf;
597
+ const wb = 0.13 + (0.24 - 0.13) * shelf;
598
+ r = wr + (lr - wr) * land;
599
+ g = wg + (lg - wg) * land;
600
+ b = wb + (lb - wb) * land;
601
+ const ice = Math.max(smooth(0.84, 0.875, ay + 0.04 * (detail - 0.5)) * land, smooth(0.9, 0.93, ay + 0.03 * (detail - 0.5)));
602
+ r += (0.92 - r) * ice; g += (0.94 - g) * ice; b += (0.96 - b) * ice;
603
+ gloss = (1 - land) * (1 - ice);
604
+ height = land * (0.12 + 0.7 * relief * ridges + 0.08 * detail);
605
+ // Clouds: swirled twice, a broad turn and a tighter one, drawn out along the latitudes, and torn
606
+ // at the edges by a finer noise so they are wisps and streets rather than lumps.
607
+ const cw = fractalNoise(x * 2.2 + 41, y * 2.2, z * 2.2, 3) - 0.5;
608
+ const cv = fractalNoise(x * 5 + 13, y * 5 + cw, z * 5, 2) - 0.5;
609
+ const cn = fractalNoise(x * 3.2 + cw * 2 + cv * 0.6, y * 6 + cw * 1.2, z * 3.2 - cw * 2 + 9 - cv * 0.6, 5);
610
+ const torn = fractalNoise(x * 16 + cv, y * 26, z * 16, 3);
611
+ const belts = 0.12 * Math.exp(-((y / 0.1) ** 2)) + 0.1 * Math.exp(-(((ay - 0.75) / 0.1) ** 2)) - 0.08 * Math.exp(-(((ay - 0.4) / 0.12) ** 2));
612
+ cloud = smooth(0.5, 0.8, cn + belts + 0.22 * (torn - 0.5)) * (0.7 + 0.3 * torn);
613
+ } else if (kind === 'question') {
614
+ // Uranus. Nearly featureless: bands a few hundredths apart in brightness, wavering a little, and
615
+ // a brighter haze over the pole that faces us.
616
+ const swirl = gradientNoise(x * 2.2 + 7, y * 2.2, z * 2.2);
617
+ const band = Math.sin(y * 16 + swirl * 0.8);
618
+ const hood = smooth(0.35, 0.85, -y);
619
+ const fine = fractalNoise(x * 5, y * 18, z * 5, 3) - 0.5;
620
+ const v = 1 + 0.022 * band + 0.07 * hood + 0.025 * fine;
621
+ r = 0.6 * v;
622
+ g = 0.84 * v;
623
+ b = 0.88 * v + 0.02 * hood;
624
+ } else {
625
+ // Mercury. Craters on three scales, fewer on the smooth plains; a fine grit; broad provinces a
626
+ // little lighter or darker; and the rays of the young craters.
627
+ const tone = fractalNoise(x * 2.1 + 5, y * 2.1, z * 2.1, 4);
628
+ const plains = smooth(0.56, 0.72, fractalNoise(x * 1.4 + 17, y * 1.4 + 3, z * 1.4, 3));
629
+ craterField(x * 3 + 40, y * 3, z * 3, 0.55);
630
+ const h1 = CRATER[0], r1 = CRATER[1];
631
+ craterField(x * 7 + 11, y * 7, z * 7, 0.6);
632
+ const h2 = CRATER[0], r2 = CRATER[1];
633
+ craterField(x * 16 + 3, y * 16, z * 16, 0.75);
634
+ const h3 = CRATER[0], r3 = CRATER[1];
635
+ const grit = gradientNoise(x * 45, y * 45, z * 45);
636
+ height = h1 + h2 * 0.5 * (1 - 0.5 * plains) + h3 * 0.22 * (1 - 0.7 * plains) + grit * 0.04;
637
+ const a = 0.4 + 0.16 * (tone - 0.5) + 0.05 * plains + 0.2 * Math.min(1, r1 + r2 * 0.7 + r3 * 0.4) + 0.02 * grit;
638
+ r = a * 1.05;
639
+ g = a;
640
+ b = a * 0.92;
641
+ }
642
+ s[0] = Math.min(1, Math.max(0, r));
643
+ s[1] = Math.min(1, Math.max(0, g));
644
+ s[2] = Math.min(1, Math.max(0, b));
645
+ s[3] = gloss;
646
+ s[4] = cloud;
647
+ s[5] = height;
648
+ return s;
649
+ }
650
+
651
+ // The whole surface of one planet: at each texel the colour, gloss, cloud and height, and the slope
652
+ // of the height east and south (per radian of arc), which is what the light reads the relief from.
653
+ // Built a band of rows at a time when asked to be (`rows`), so the work can be spread over frames;
654
+ // the map is handed out only once it is whole, slopes and all.
655
+ const PLANET_STRIDE = 8;
656
+ const planetMaps = new Map();
657
+ function planetMap(kind, rows = ALBEDO_H) {
658
+ const key = planetOf(kind);
659
+ let build = planetMaps.get(key);
544
660
  if (build?.done) return build.map;
545
661
  if (!build) {
546
- const offset = [...String(kind)].reduce((sum, letter) => sum + letter.charCodeAt(0), 0) * 0.37;
547
- build = { offset, map: new Float32Array(ALBEDO_W * ALBEDO_H * 2), next: 0, done: false };
548
- dwarfAlbedos.set(kind, build);
662
+ build = { map: new Float32Array(ALBEDO_W * ALBEDO_H * PLANET_STRIDE), next: 0, done: false };
663
+ planetMaps.set(key, build);
549
664
  }
550
- const { offset, map } = build;
665
+ const { map } = build;
666
+ const texel = new Float32Array(6);
551
667
  const until = Math.min(ALBEDO_H, build.next + rows);
552
668
  for (let row = build.next; row < until; row += 1) {
553
669
  const lat = ((row + 0.5) / ALBEDO_H - 0.5) * Math.PI;
554
670
  const cl = Math.cos(lat), sl = Math.sin(lat);
555
671
  for (let col = 0; col < ALBEDO_W; col += 1) {
556
- const lon = ((col + 0.5) / ALBEDO_W) * Math.PI * 2;
557
- const px = cl * Math.cos(lon) + offset, py = sl, pz = cl * Math.sin(lon);
558
- // Granules: bright where a cell's middle is, dark along the lanes between cells, and a
559
- // slow unevenness over the lot so no two stretches of the surface match.
560
- const drift = fractalNoise(px * 3 + 4, py * 3, pz * 3, 3) - 0.5;
561
- const [near, next] = cellNoise(px * 21 + drift, py * 21, pz * 21 - drift);
562
- const lane = smooth(0, 0.32, next - near);
563
- const middle = 1 - Math.min(1, near * 0.9);
564
- const granule = 0.5 + 0.5 * (lane * (0.6 + 0.4 * middle) - 0.55) + 0.18 * (fractalNoise(px * 6, py * 6 + 2, pz * 6, 3) - 0.5);
565
- // The field: where it is strongest, spots; in a ring around them, faculae.
566
- const field = fractalNoise(px * 2.3 + 11, py * 2.3, pz * 2.3, 4) + 0.06 * (fractalNoise(px * 9, py * 9, pz * 9, 2) - 0.5);
567
- const at = (row * ALBEDO_W + col) * 2;
568
- map[at] = Math.min(1, Math.max(0, granule));
569
- map[at + 1] = field;
672
+ const lon = (col / ALBEDO_W) * Math.PI * 2;
673
+ planetSurface(key, cl * Math.sin(lon), sl, cl * Math.cos(lon), texel);
674
+ map.set(texel, (row * ALBEDO_W + col) * PLANET_STRIDE);
570
675
  }
571
676
  }
572
677
  build.next = until;
573
- build.done = until >= ALBEDO_H;
574
- return build.done ? map : null;
678
+ if (until < ALBEDO_H) return null;
679
+ const east = (2 * Math.PI) / ALBEDO_W;
680
+ const south = Math.PI / ALBEDO_H;
681
+ for (let row = 0; row < ALBEDO_H; row += 1) {
682
+ const cl = Math.max(0.2, Math.cos(((row + 0.5) / ALBEDO_H - 0.5) * Math.PI));
683
+ const up = Math.max(0, row - 1), down = Math.min(ALBEDO_H - 1, row + 1);
684
+ for (let col = 0; col < ALBEDO_W; col += 1) {
685
+ const at = (row * ALBEDO_W + col) * PLANET_STRIDE;
686
+ const left = (row * ALBEDO_W + ((col + ALBEDO_W - 1) % ALBEDO_W)) * PLANET_STRIDE;
687
+ const right = (row * ALBEDO_W + ((col + 1) % ALBEDO_W)) * PLANET_STRIDE;
688
+ map[at + 6] = (map[right + 5] - map[left + 5]) / (2 * east * cl);
689
+ map[at + 7] = (map[(down * ALBEDO_W + col) * PLANET_STRIDE + 5] - map[(up * ALBEDO_W + col) * PLANET_STRIDE + 5]) / ((down - up) * south);
690
+ }
691
+ }
692
+ build.done = true;
693
+ return map;
575
694
  }
576
695
 
696
+
577
697
  // Every pixel of a disc `size` pixels across: which way it faces, where on the map it reads,
578
698
  // and how much of it the disc covers, so the edge is smooth without a second pass.
579
699
  function sphereTable(size) {
@@ -599,75 +719,454 @@ function sphereTable(size) {
599
719
  return table;
600
720
  }
601
721
 
602
- // The shading itself. Pure: a table, a map and the star in, RGBA out. `colour` is the class's
603
- // colour as three numbers 0..1, `surface` what its standing does to it (surfaceOf), `turn` how
604
- // far the body has spun, `burn` how hard it burns.
605
- function shadeDwarf(out, table, map, { colour, traits = SUN_TRAITS, surface = surfaceOf(null, traits), turn, burn }) {
722
+ // Every pixel of a planet's painted face, `size` pixels across with its disc `halo` times smaller,
723
+ // so the air has room past the limb. For the disc: where it is, which way it faces, where on the
724
+ // map it reads, how much of the pixel the disc covers, and which ways east and south run there (the
725
+ // relief tilts the light along those). For the ring past the limb: which way it points and how far
726
+ // out it is. Worked out once per size and kept.
727
+ const globeTables = new Map();
728
+ function globeTable(size, halo = 1) {
729
+ const key = `${size}:${halo}`;
730
+ if (globeTables.has(key)) return globeTables.get(key);
731
+ const half = size / 2;
732
+ const R = half / halo;
733
+ const disc = [];
734
+ const ring = [];
735
+ for (let py = 0; py < size; py += 1) {
736
+ for (let px = 0; px < size; px += 1) {
737
+ const x = (px + 0.5 - half) / R;
738
+ const y = (py + 0.5 - half) / R;
739
+ const rr = x * x + y * y;
740
+ const rho = Math.sqrt(rr);
741
+ const cover = Math.min(1, Math.max(0, (1 - rho) * R + 0.5));
742
+ if (cover > 0) {
743
+ const z = Math.sqrt(Math.max(0, 1 - rr));
744
+ const lon = Math.atan2(x, z);
745
+ const lat = Math.asin(Math.max(-1, Math.min(1, y)));
746
+ const v = Math.max(0, Math.min(ALBEDO_H - 1.001, (lat / Math.PI + 0.5) * ALBEDO_H - 0.5));
747
+ const cl = Math.hypot(x, z) || 1e-6;
748
+ disc.push(py * size + px, x, y, z, (lon / (Math.PI * 2)) * ALBEDO_W, v, cover, z / cl, -x / cl, (-y * x) / cl, cl, (-y * z) / cl);
749
+ }
750
+ if (halo > 1 && cover < 1 && rho < halo) ring.push(py * size + px, x / (rho || 1), y / (rho || 1), rho, cover);
751
+ }
752
+ }
753
+ const table = { size, halo, disc: Float32Array.from(disc), ring: Float32Array.from(ring) };
754
+ globeTables.set(key, table);
755
+ return table;
756
+ }
757
+
758
+ // One point of a planet in the light. `s` is what is there (planetSurface, or the map read between
759
+ // texels), (x, y, z) where it is on the sphere in view space, (ex, ez) and (sx, sy, sz) the ways east
760
+ // and south run there, `L` the direction of the sun and `H` the half-way direction between the sun
761
+ // and the eye (for the glint). Writes the colour as seen, 0..1, into `rgb`.
762
+ function lightTexel(planet, s, x, y, z, ex, ez, sx, sy, sz, L, H, exposure, fade, fill, rgb) {
763
+ const k = planet.bump;
764
+ let nx = x - k * (s[6] * ex + s[7] * sx);
765
+ let ny = y - k * s[7] * sy;
766
+ let nz = z - k * (s[6] * ez + s[7] * sz);
767
+ const nn = 1 / Math.sqrt(nx * nx + ny * ny + nz * nz);
768
+ nx *= nn; ny *= nn; nz *= nn;
769
+ // Where day ends is the sphere's business; the relief only tilts the light within it.
770
+ const geo = x * L[0] + y * L[1] + z * L[2];
771
+ const lit = nx * L[0] + ny * L[1] + nz * L[2];
772
+ const mu = Math.max(0.0001, z);
773
+ let day;
774
+ if (planet.rocky) {
775
+ const d = Math.max(0, lit);
776
+ day = (0.62 * d + (0.76 * d) / (d + Math.max(mu, 0.25))) * smooth(-0.1, 0.06, geo);
777
+ } else {
778
+ const w = planet.wrap;
779
+ day = Math.max(0, (lit + w) / (1 + w)) * smooth(-1.5 * w, w, geo) * (1 - planet.limb * (1 - Math.sqrt(mu)));
780
+ }
781
+ let ar = s[0], ag = s[1], ab = s[2];
782
+ const cloud = planet.clouds ? s[4] : 0;
783
+ if (cloud) { ar += (0.93 - ar) * cloud; ag += (0.94 - ag) * cloud; ab += (0.96 - ab) * cloud; }
784
+ let lr = day * SUN_LIGHT[0] * exposure;
785
+ let lg = day * SUN_LIGHT[1] * exposure;
786
+ let lb = day * SUN_LIGHT[2] * exposure;
787
+ if (planet.air && !planet.rocky) {
788
+ // Sunset along the terminator: the light that reaches it has crossed the most air.
789
+ const dusk = smooth(-0.02, 0.3, geo);
790
+ lg *= 0.8 + 0.2 * dusk;
791
+ lb *= 0.6 + 0.4 * dusk;
792
+ }
793
+ const ambient = PLANET_AMBIENT + fill * (0.16 + 0.2 * mu);
794
+ let r = ar * ar * (lr + ambient);
795
+ let g = ag * ag * (lg + ambient);
796
+ let b = ab * ab * (lb + ambient);
797
+ if (planet.ocean && geo > 0) {
798
+ const wet = s[3] * (1 - cloud);
799
+ if (wet > 0.01) {
800
+ const nh = Math.max(0, nx * H[0] + ny * H[1] + nz * H[2]);
801
+ const glint = wet * (0.55 * nh ** 70 + 0.05 * nh ** 8) * smooth(0, 0.18, geo) * exposure;
802
+ r += glint; g += glint * 0.96; b += glint * 0.9;
803
+ }
804
+ }
805
+ if (planet.air) {
806
+ // The air over the disc: thicker toward the limb, lit where the sun is.
807
+ const haze = (1 - mu) ** 2.2 * smooth(-0.25, 0.35, geo) * planet.airGlow * 0.42 * exposure;
808
+ r += planet.air[0] * planet.air[0] * haze;
809
+ g += planet.air[1] * planet.air[1] * haze;
810
+ b += planet.air[2] * planet.air[2] * haze;
811
+ }
812
+ if (fade > 0) {
813
+ // Out of circulation: the colour goes out of it and it dims, as the faded stars used to.
814
+ const grey = 0.3 * r + 0.59 * g + 0.11 * b;
815
+ const keep = 1 - 0.55 * fade;
816
+ r = (r + (grey - r) * 0.8 * fade) * keep;
817
+ g = (g + (grey - g) * 0.8 * fade) * keep;
818
+ b = (b + (grey - b) * 0.8 * fade) * keep;
819
+ }
820
+ rgb[0] = Math.sqrt(Math.min(1, r));
821
+ rgb[1] = Math.sqrt(Math.min(1, g));
822
+ rgb[2] = Math.sqrt(Math.min(1, b));
823
+ return rgb;
824
+ }
825
+
826
+ // The halo of the air past the limb, laid over what the disc already painted: lit on the side the
827
+ // sun is on, and all the way round when the sun is behind the planet and the air is seen against it.
828
+ // Never thinner than about a pixel, so a small planet crossing the sun still shows its ring of air.
829
+ function haloInto(out, table, planet, L, exposure, fade) {
830
+ if (!planet.air || !table.ring.length) return out;
831
+ const ring = table.ring;
832
+ const behind = Math.max(0, -L[2]) ** 1.5;
833
+ const glow = planet.airGlow * exposure * (1 - 0.6 * fade);
834
+ const thickness = Math.max(planet.thickness, (1.2 * table.halo * 2) / table.size);
835
+ for (let i = 0; i < ring.length; i += 5) {
836
+ const p = ring[i] * 4;
837
+ const rho = ring[i + 3];
838
+ const facing = ring[i + 1] * L[0] + ring[i + 2] * L[1];
839
+ const lit = Math.max(smooth(-0.2, 0.5, facing) * (0.8 + 0.4 * behind), 0.8 * behind);
840
+ const a = Math.min(1, glow * lit * Math.exp(-Math.max(0, rho - 1) / thickness));
841
+ if (a <= 0.002) continue;
842
+ const under = out[p + 3] / 255;
843
+ const alpha = under + a * (1 - under);
844
+ for (let c = 0; c < 3; c += 1) out[p + c] = Math.min(255, (out[p + c] * under + 255 * planet.air[c] * a) / alpha);
845
+ out[p + 3] = 255 * alpha;
846
+ }
847
+ return out;
848
+ }
849
+
850
+ // The shading itself. Pure: a table (globeTable), the map (planetMap) and the moment in, RGBA out.
851
+ // `light` is the direction of the sun in view space (x right, y down, z toward the eye), `turn` how
852
+ // far the body has spun, `exposure` how much of the light it shows (what the room has made of it),
853
+ // `fade` whether it is out of circulation, `fill` how much a held planet is lit from the front.
854
+ function shadePlanet(out, table, map, { kind, light, turn = 0, exposure = 1, fade = 0, fill = 0 }) {
606
855
  out.fill(0);
607
- const shift = (((turn / (Math.PI * 2)) % 1) + 1) % 1 * ALBEDO_W;
608
- const energy = (0.62 + 0.62 * burn) * (traits.power ?? 1);
609
- const whiten = traits.white * (0.5 + 0.5 * burn);
610
- // Toward the edge the class's colour deepens: cooler gas, the same hue, more of it.
611
- const deep = colour.map((value) => value ** 1.6);
612
- const cells = table.cells;
613
- const sample = new Float32Array(2);
614
- const { spots, reach, faculae, granules } = surface;
615
- const energyNow = energy * (surface.glow ?? 1);
616
- const whitenNow = whiten * (surface.white ?? 1);
617
- for (let i = 0; i < cells.length; i += 7) {
618
- const mu = cells[i + 3];
619
- // Read between texels, never from one: the map is smaller than a close-up body, and a body
620
- // read texel by texel shows them as squares.
621
- const u = cells[i + 4] + shift;
856
+ const planet = PLANETS[planetOf(kind)];
857
+ const L = light;
858
+ const hz = L[2] + 1;
859
+ const hn = Math.hypot(L[0], L[1], hz) || 1;
860
+ const H = [L[0] / hn, L[1] / hn, hz / hn];
861
+ const shift = ((((turn / (Math.PI * 2)) % 1) + 1) % 1) * ALBEDO_W;
862
+ // The clouds keep their own pace over the ground.
863
+ const drift = planet.clouds ? ((((turn * 0.08) / (Math.PI * 2)) % 1) + 1) % 1 * ALBEDO_W : 0;
864
+ const cells = table.disc;
865
+ const s = new Float32Array(PLANET_STRIDE);
866
+ const rgb = [0, 0, 0];
867
+ const read = (u, v, channel) => {
622
868
  const u0 = Math.floor(u);
623
869
  const fu = u - u0;
624
870
  const c0 = ((u0 % ALBEDO_W) + ALBEDO_W) % ALBEDO_W;
625
871
  const c1 = (c0 + 1) % ALBEDO_W;
872
+ const r0 = Math.floor(v);
873
+ const fv = v - r0;
874
+ const r1 = Math.min(ALBEDO_H - 1, r0 + 1);
875
+ const a = (r0 * ALBEDO_W + c0) * PLANET_STRIDE + channel, b = (r0 * ALBEDO_W + c1) * PLANET_STRIDE + channel;
876
+ const c = (r1 * ALBEDO_W + c0) * PLANET_STRIDE + channel, d = (r1 * ALBEDO_W + c1) * PLANET_STRIDE + channel;
877
+ return (map[a] * (1 - fu) + map[b] * fu) * (1 - fv) + (map[c] * (1 - fu) + map[d] * fu) * fv;
878
+ };
879
+ for (let i = 0; i < cells.length; i += 12) {
880
+ // Read between texels, never from one: a close planet is larger than its map.
881
+ const u = cells[i + 4] + shift;
626
882
  const v = cells[i + 5];
883
+ const u0 = Math.floor(u);
884
+ const fu = u - u0;
885
+ const c0 = ((u0 % ALBEDO_W) + ALBEDO_W) % ALBEDO_W;
886
+ const c1 = (c0 + 1) % ALBEDO_W;
627
887
  const r0 = Math.floor(v);
628
888
  const fv = v - r0;
629
889
  const r1 = Math.min(ALBEDO_H - 1, r0 + 1);
630
- for (let k = 0; k < 2; k += 1) {
631
- const top = map[(r0 * ALBEDO_W + c0) * 2 + k] * (1 - fu) + map[(r0 * ALBEDO_W + c1) * 2 + k] * fu;
632
- const bottom = map[(r1 * ALBEDO_W + c0) * 2 + k] * (1 - fu) + map[(r1 * ALBEDO_W + c1) * 2 + k] * fu;
633
- sample[k] = top * (1 - fv) + bottom * fv;
634
- }
635
- const [granule, field] = sample;
636
- // Spots where the field passes `reach`, umbra deeper in; faculae in the ring just short of it.
637
- const ring = smooth(reach, reach + 0.07, field);
638
- const umbra = smooth(reach + 0.07, reach + 0.12, field) * spots;
639
- const penumbra = ring * spots;
640
- const facula = Math.max(0, smooth(reach - 0.11, reach - 0.01, field) - ring) * faculae;
641
- // The cells foreshorten toward the limb and their contrast goes with them.
642
- const cells_ = 1 + granules * 0.62 * (granule - 0.5) * Math.sqrt(mu);
643
- const bright = 1 + 0.6 * facula * (1 - mu) ** 0.7;
644
- const dark = 1 - 0.8 * umbra - 0.4 * Math.max(0, penumbra - umbra);
645
- // White-hot in the middle, its own colour toward the edge, deepening at the limb.
646
- const heat = whitenNow * mu * mu;
647
- const edge = (1 - mu) ** 1.5;
890
+ const a = (r0 * ALBEDO_W + c0) * PLANET_STRIDE, b = (r0 * ALBEDO_W + c1) * PLANET_STRIDE;
891
+ const c = (r1 * ALBEDO_W + c0) * PLANET_STRIDE, d = (r1 * ALBEDO_W + c1) * PLANET_STRIDE;
892
+ const wa = (1 - fu) * (1 - fv), wb = fu * (1 - fv), wc = (1 - fu) * fv, wd = fu * fv;
893
+ for (let k = 0; k < PLANET_STRIDE; k += 1) s[k] = map[a + k] * wa + map[b + k] * wb + map[c + k] * wc + map[d + k] * wd;
894
+ if (planet.clouds) s[4] = read(cells[i + 4] + shift + drift, v, 4);
895
+ lightTexel(planet, s, cells[i + 1], cells[i + 2], cells[i + 3], cells[i + 7], cells[i + 8], cells[i + 9], cells[i + 10], cells[i + 11], L, H, exposure, fade, fill, rgb);
648
896
  const p = cells[i] * 4;
649
- for (let k = 0; k < 3; k += 1) {
650
- const hue = colour[k] + (deep[k] - colour[k]) * edge;
651
- const tint = hue + (1 - hue) * heat;
652
- const limb = 1 - LIMB_DARKENING[k] * (1 - mu);
653
- const value = tint * limb * cells_ * bright * dark * energyNow;
654
- out[p + k] = 255 * (1 - Math.exp(-value * 2.6));
655
- }
897
+ out[p] = 255 * rgb[0];
898
+ out[p + 1] = 255 * rgb[1];
899
+ out[p + 2] = 255 * rgb[2];
656
900
  out[p + 3] = 255 * cells[i + 6];
657
901
  }
658
- return out;
902
+ return haloInto(out, table, planet, L, exposure, fade);
903
+ }
904
+
905
+ // ---- The legend's planets (2026-11-15; the stars before them moved here from app.js on 2026-10-10,
906
+ // so the Project map draws the same ones as the Memory map). The same planet the map paints, small:
907
+ // the same surface and the same light, the sun high on the left and a little in front, so each shows
908
+ // its day, its terminator and a sliver of night. Read straight from the surface at each pixel, so it
909
+ // needs no map built first and is ready the moment the legend is. Painted at twice its size and
910
+ // brought down, so the craters and the clouds settle into the few pixels they have instead of
911
+ // speckling them; made once per planet and size, and copied for every legend that asks.
912
+ const CHIP_LIGHT = (() => { const l = [-0.62, -0.46, 0.64]; const n = Math.hypot(...l); return l.map((value) => value / n); })();
913
+ // As much of the light as a memory the room has used a little shows on the map.
914
+ const CHIP_EXPOSURE = 1.2;
915
+ const chipFaces = new Map();
916
+ export function planetChip(kind, px, { faded = false } = {}) {
917
+ const canvas = document.createElement('canvas');
918
+ const dpr = Math.min(3, window.devicePixelRatio || 1);
919
+ const size = Math.max(4, Math.round(px * dpr));
920
+ canvas.width = size;
921
+ canvas.height = size;
922
+ canvas.style.width = `${px}px`;
923
+ canvas.style.height = `${px}px`;
924
+ const paint = canvas.getContext('2d');
925
+ if (!paint?.createImageData) return canvas;
926
+ const key = `${planetOf(kind)}:${size}:${faded ? 1 : 0}`;
927
+ let face = chipFaces.get(key);
928
+ if (!face) {
929
+ face = chipFace(planetOf(kind), size * 2, faded);
930
+ chipFaces.set(key, face);
931
+ }
932
+ if (face) {
933
+ paint.imageSmoothingQuality = 'high';
934
+ paint.drawImage(face, 0, 0, size, size);
935
+ }
936
+ return canvas;
937
+ }
938
+ function chipFace(key, size, faded) {
939
+ const canvas = document.createElement('canvas');
940
+ canvas.width = size;
941
+ canvas.height = size;
942
+ const paint = canvas.getContext('2d');
943
+ if (!paint?.createImageData) return null;
944
+ const planet = PLANETS[key];
945
+ const table = globeTable(size, planet.air ? 1.1 : 1);
946
+ const image = paint.createImageData(size, size);
947
+ const out = image.data;
948
+ const L = CHIP_LIGHT;
949
+ const hn = Math.hypot(L[0], L[1], L[2] + 1);
950
+ const H = [L[0] / hn, L[1] / hn, (L[2] + 1) / hn];
951
+ const s = new Float32Array(PLANET_STRIDE);
952
+ const t = new Float32Array(6);
953
+ const rgb = [0, 0, 0];
954
+ // The relief is read a pixel apart: finer than that, it is noise the chip cannot show.
955
+ const step = 2.2 / size;
956
+ const cells = table.disc;
957
+ const at = (lon, lat, into) => { const cl = Math.cos(lat); return planetSurface(key, cl * Math.sin(lon), Math.sin(lat), cl * Math.cos(lon), into); };
958
+ for (let i = 0; i < cells.length; i += 12) {
959
+ const x = cells[i + 1], y = cells[i + 2], z = cells[i + 3];
960
+ const lon = Math.atan2(x, z) + planet.face;
961
+ const lat = Math.asin(Math.max(-1, Math.min(1, y)));
962
+ at(lon, lat, s);
963
+ const height = s[5];
964
+ s[6] = (at(lon + step, lat, t)[5] - height) / (step * Math.max(0.2, Math.cos(lat)));
965
+ s[7] = (at(lon, lat + step, t)[5] - height) / step;
966
+ lightTexel(planet, s, x, y, z, cells[i + 7], cells[i + 8], cells[i + 9], cells[i + 10], cells[i + 11], L, H, CHIP_EXPOSURE, faded ? 1 : 0, 0, rgb);
967
+ const p = cells[i] * 4;
968
+ out[p] = 255 * rgb[0];
969
+ out[p + 1] = 255 * rgb[1];
970
+ out[p + 2] = 255 * rgb[2];
971
+ out[p + 3] = 255 * cells[i + 6];
972
+ }
973
+ haloInto(out, table, planet, L, CHIP_EXPOSURE, faded ? 1 : 0);
974
+ paint.putImageData(image, 0, 0);
975
+ return canvas;
976
+ }
977
+
978
+ // ---- The aberration: a black hole (2026-11-15, asked by the author: «el agujero negro de la
979
+ // aberración también hacerlo más profundo»).
980
+ //
981
+ // A claim the room established is false, drawn as the one thing out here that gives nothing back.
982
+ // From the back to the front:
983
+ // the pull: the dark reaches past the hole and dims whatever is behind it, wires and dust alike;
984
+ // the field behind it, bent: every speck of dust is seen where the hole's gravity throws its light,
985
+ // pushed out to a ring and stretched along it, and a second, fainter image on the far side;
986
+ // the far half of its disc, and the light of that far half lifted over the top of the hole and
987
+ // under the bottom, which is what a disc round a black hole looks like seen nearly edge on;
988
+ // the horizon: black, all of it, with nothing painted inside;
989
+ // the ring of light that has gone round the hole before reaching us, tight against the black;
990
+ // the near half of the disc, crossing in front of the hole.
991
+ // The disc is cold, the aberration's violet running to white at its inner edge, and brighter on the
992
+ // side that turns toward us. Its streaks go round, the inner ones faster; not for whoever asked for
993
+ // stillness. Nothing about it is warm, so it does not read as a sun, and nothing about it is a
994
+ // planet, so it does not read as knowledge.
995
+ const HOLE_DISC_IN = 1.16; // the disc's inner edge, in radii of the black
996
+ const HOLE_DISC_OUT = 2.8; // and its outer edge
997
+ const HOLE_TILT = 0.2; // how open the disc is to us: nearly edge on
998
+ const HOLE_EINSTEIN = 1.3; // where the light of what is behind it gathers into a ring
999
+ const HOLE_STREAKS = 7;
1000
+ const rgbOf = (hex) => [1, 3, 5].map((at) => Number.parseInt(String(hex).slice(at, at + 2), 16));
1001
+ export function drawBlackHole(ctx, x, y, S, { t = 0, turn = 0, roll = 0, lit = 1, px = 1, still = false, colour = MEMORY_COLORS.aberration, dust = VOID_DUST.length, streaks = HOLE_STREAKS } = {}) {
1002
+ const tone = rgbOf(colour);
1003
+ if (tone.some((value) => !Number.isFinite(value))) tone.splice(0, 3, 177, 76, 255);
1004
+ const violet = tone.join(', ');
1005
+ const pale = tone.map((value) => Math.round(value + (255 - value) * 0.6)).join(', ');
1006
+ const deep = tone.map((value, i) => Math.round(value * [0.35, 0.3, 0.62][i])).join(', ');
1007
+ const k = 0.75 + 0.25 * Math.max(0, Math.min(1, lit));
1008
+ ctx.save();
1009
+ ctx.translate(x, y);
1010
+ ctx.rotate(roll);
1011
+ // The pull.
1012
+ ctx.globalCompositeOperation = 'source-over';
1013
+ const pull = ctx.createRadialGradient(0, 0, S * 0.9, 0, 0, S * 2.3);
1014
+ pull.addColorStop(0, 'rgba(0, 0, 0, .9)');
1015
+ pull.addColorStop(0.45, 'rgba(0, 0, 0, .42)');
1016
+ pull.addColorStop(1, 'rgba(0, 0, 0, 0)');
1017
+ ctx.fillStyle = pull;
1018
+ ctx.beginPath(); ctx.arc(0, 0, S * 2.3, 0, Math.PI * 2); ctx.fill();
1019
+
1020
+ ctx.globalCompositeOperation = 'lighter';
1021
+ // The field behind it, bent (the lens equation: a speck truly at `beta` is seen at the two roots).
1022
+ const ring = S * HOLE_EINSTEIN;
1023
+ for (let i = 0; i < Math.min(dust, VOID_DUST.length); i += 1) {
1024
+ const speck = VOID_DUST[i];
1025
+ const beta = S * (0.15 + 2.9 * speck.out);
1026
+ const root = Math.sqrt(beta * beta + 4 * ring * ring);
1027
+ const fade = 0.7 * (1 - speck.out * 0.6) * k * (still ? 0.75 : 0.45 + 0.55 * Math.abs(Math.sin(t * speck.rate + speck.phase)));
1028
+ const size = speck.size * px;
1029
+ for (const [seen, side, weight] of [[(beta + root) / 2, 0, 1], [(root - beta) / 2, Math.PI, 0.45]]) {
1030
+ if (seen < S * 1.03) continue;
1031
+ const angle = speck.angle + turn + side;
1032
+ const stretch = Math.min(3.5, seen / Math.max(beta, S * 0.2));
1033
+ ctx.save();
1034
+ ctx.translate(Math.cos(angle) * seen, Math.sin(angle) * seen);
1035
+ ctx.rotate(angle);
1036
+ ctx.scale(1, stretch);
1037
+ const glow = ctx.createRadialGradient(0, 0, 0, 0, 0, size * 2.6);
1038
+ glow.addColorStop(0, `rgba(${speck.colour}, ${fade * weight})`);
1039
+ glow.addColorStop(0.35, `rgba(${speck.colour}, ${fade * weight * 0.3})`);
1040
+ glow.addColorStop(1, `rgba(${speck.colour}, 0)`);
1041
+ ctx.fillStyle = glow;
1042
+ ctx.beginPath(); ctx.arc(0, 0, size * 2.6, 0, Math.PI * 2); ctx.fill();
1043
+ ctx.restore();
1044
+ }
1045
+ }
1046
+
1047
+ // Half of the disc, the far half (behind the black) or the near one (in front of it).
1048
+ const inner = S * HOLE_DISC_IN;
1049
+ const outer = S * HOLE_DISC_OUT;
1050
+ const disc = (near) => {
1051
+ const from = near ? 0 : Math.PI;
1052
+ const to = from + Math.PI;
1053
+ ctx.save();
1054
+ ctx.scale(1, HOLE_TILT);
1055
+ ctx.beginPath(); ctx.arc(0, 0, outer, from, to); ctx.arc(0, 0, inner, to, from, true); ctx.closePath();
1056
+ const body = ctx.createRadialGradient(0, 0, inner, 0, 0, outer);
1057
+ body.addColorStop(0, `rgba(250, 244, 255, ${0.92 * k})`);
1058
+ body.addColorStop(0.3, `rgba(${pale}, ${0.78 * k})`);
1059
+ body.addColorStop(0.62, `rgba(${violet}, ${0.48 * k})`);
1060
+ body.addColorStop(0.88, `rgba(${deep}, ${0.16 * k})`);
1061
+ body.addColorStop(1, `rgba(${deep}, 0)`);
1062
+ ctx.fillStyle = body;
1063
+ ctx.fill();
1064
+ // The side turning toward us is the brighter one: a light over the left of the ring that is
1065
+ // gone before the ring's edges, so it adds no edge of its own.
1066
+ const lobe = (outer - inner) * 0.62;
1067
+ const beam = ctx.createRadialGradient(-(inner + outer) / 2, 0, 0, -(inner + outer) / 2, 0, lobe);
1068
+ beam.addColorStop(0, `rgba(236, 226, 255, ${0.45 * k})`);
1069
+ beam.addColorStop(1, 'rgba(236, 226, 255, 0)');
1070
+ ctx.fillStyle = beam;
1071
+ ctx.fill();
1072
+ // The streaks: the inner ones go round faster.
1073
+ ctx.lineCap = 'round';
1074
+ for (let n = 0; n < streaks; n += 1) {
1075
+ const along = 0.08 + 0.8 * frac(n * 0.618);
1076
+ const radius = inner + (outer - inner) * along;
1077
+ const start = n * 2.39996 + turn + (still ? 0 : t * 0.9 * (inner / radius) ** 1.5);
1078
+ const span = 0.35 + 0.5 * frac(n * 0.37);
1079
+ ctx.strokeStyle = `rgba(242, 234, 255, ${0.2 * k * (1 - along)})`;
1080
+ ctx.lineWidth = Math.max(px * 0.7, S * 0.035);
1081
+ for (const lap of [-Math.PI * 2, 0, Math.PI * 2]) {
1082
+ const a = Math.max(from, (((start % (Math.PI * 2)) + Math.PI * 2) % (Math.PI * 2)) + lap);
1083
+ const b = Math.min(to, (((start % (Math.PI * 2)) + Math.PI * 2) % (Math.PI * 2)) + lap + span);
1084
+ if (b > a) { ctx.beginPath(); ctx.arc(0, 0, radius, a, b); ctx.stroke(); }
1085
+ }
1086
+ }
1087
+ ctx.restore();
1088
+ };
1089
+ disc(false);
1090
+ // The far half's light, lifted over the top of the hole: a band hugging the black, brightest
1091
+ // against it, thickest at the top and thinning to where it meets the disc at the sides; and,
1092
+ // much thinner, the same under the bottom.
1093
+ ctx.save();
1094
+ ctx.scale(1, 1.16);
1095
+ ctx.beginPath(); ctx.arc(0, 0, S * 1.38, Math.PI, Math.PI * 2); ctx.closePath();
1096
+ const over = ctx.createRadialGradient(0, 0, S * 0.8, 0, 0, S * 1.38);
1097
+ over.addColorStop(0, `rgba(${pale}, 0)`);
1098
+ over.addColorStop(0.24, `rgba(250, 244, 255, ${0.82 * k})`);
1099
+ over.addColorStop(0.42, `rgba(${pale}, ${0.5 * k})`);
1100
+ over.addColorStop(0.72, `rgba(${violet}, ${0.18 * k})`);
1101
+ over.addColorStop(1, `rgba(${violet}, 0)`);
1102
+ ctx.fillStyle = over;
1103
+ ctx.fill();
1104
+ ctx.restore();
1105
+ ctx.beginPath(); ctx.arc(0, 0, S * 1.12, 0, Math.PI); ctx.closePath();
1106
+ const under = ctx.createRadialGradient(0, 0, S * 0.95, 0, 0, S * 1.12);
1107
+ under.addColorStop(0, `rgba(${pale}, 0)`);
1108
+ under.addColorStop(0.4, `rgba(${pale}, ${0.22 * k})`);
1109
+ under.addColorStop(1, `rgba(${violet}, 0)`);
1110
+ ctx.fillStyle = under;
1111
+ ctx.fill();
1112
+
1113
+ // The horizon.
1114
+ ctx.globalCompositeOperation = 'source-over';
1115
+ const black = ctx.createRadialGradient(0, 0, 0, 0, 0, S * 1.02);
1116
+ black.addColorStop(0, 'rgba(0, 0, 0, 1)');
1117
+ black.addColorStop(0.95, 'rgba(0, 0, 0, 1)');
1118
+ black.addColorStop(1, 'rgba(0, 0, 0, 0)');
1119
+ ctx.fillStyle = black;
1120
+ ctx.beginPath(); ctx.arc(0, 0, S * 1.02, 0, Math.PI * 2); ctx.fill();
1121
+
1122
+ // The ring of light that went round the hole first, brighter on the side the disc comes from.
1123
+ ctx.globalCompositeOperation = 'lighter';
1124
+ ctx.beginPath(); ctx.arc(0, 0, S * 1.07, 0, Math.PI * 2); ctx.arc(0, 0, S * 0.98, Math.PI * 2, 0, true); ctx.closePath();
1125
+ const photons = ctx.createRadialGradient(0, 0, S * 0.98, 0, 0, S * 1.07);
1126
+ photons.addColorStop(0, 'rgba(255, 252, 255, 0)');
1127
+ photons.addColorStop(0.35, `rgba(255, 252, 255, ${0.6 * k})`);
1128
+ photons.addColorStop(0.6, `rgba(${pale}, ${0.2 * k})`);
1129
+ photons.addColorStop(1, `rgba(${violet}, 0)`);
1130
+ ctx.fillStyle = photons;
1131
+ ctx.fill();
1132
+ const side = ctx.createRadialGradient(-S * 0.7, 0, 0, -S * 0.7, 0, S * 1.3);
1133
+ side.addColorStop(0, `rgba(240, 232, 255, ${0.24 * k})`);
1134
+ side.addColorStop(1, 'rgba(240, 232, 255, 0)');
1135
+ ctx.fillStyle = side;
1136
+ ctx.fill();
1137
+
1138
+ disc(true);
1139
+ ctx.globalCompositeOperation = 'source-over';
1140
+ ctx.restore();
1141
+ }
1142
+
1143
+ // The black hole, small enough for a chip: the same drawing, still.
1144
+ export function collapsedChip(hex, px) {
1145
+ const canvas = document.createElement('canvas');
1146
+ const dpr = Math.min(3, window.devicePixelRatio || 1);
1147
+ canvas.width = Math.round(px * dpr);
1148
+ canvas.height = Math.round(px * dpr);
1149
+ canvas.style.width = `${px}px`;
1150
+ canvas.style.height = `${px}px`;
1151
+ const paint = canvas.getContext('2d');
1152
+ if (!paint) return canvas;
1153
+ paint.scale(dpr, dpr);
1154
+ const r = px / 2;
1155
+ // The black at a third of the chip, so the disc runs nearly to its edges.
1156
+ drawBlackHole(paint, r, r, r * 0.34, { px: 0.3, lit: 0.9, still: true, colour: hex, dust: 14, streaks: 2, turn: 0.4 });
1157
+ return canvas;
659
1158
  }
660
1159
 
661
- // One dwarf's painted face, kept on its node and painted again only when it has changed enough
662
- // to be seen. Null where there is no pixel buffer to paint into, and the body is drawn the
663
- // older way instead.
1160
+ // One planet's painted face, kept on its node and painted again only when it has changed enough to
1161
+ // be seen. Null where there is no pixel buffer to paint into, and the planet is drawn the plainer
1162
+ // way instead.
664
1163
  //
665
- // What it costs is bounded per frame. A surface map is built one class a frame, so opening the
666
- // map never stalls; until its class is ready a dwarf is drawn the older way. And only so many
667
- // faces are painted again each frame, in the order they are drawn; the rest keep last frame's
668
- // face for one more, which at the pace these bodies turn nobody can tell from a fresh one.
1164
+ // What it costs is bounded per frame. A surface map is built one planet a frame, a band of rows at a
1165
+ // time, so opening the map never stalls; until its planet is ready a memory is drawn the plainer
1166
+ // way. And only so many faces are painted again each frame, in the order they are drawn; the rest
1167
+ // keep last frame's face for one more, which at the pace these bodies turn nobody can tell.
669
1168
  const SHADE_BUDGET = 28;
670
- const ALBEDO_ROWS_PER_FRAME = 12;
1169
+ const PLANET_ROWS_PER_FRAME = 8;
671
1170
 
672
1171
  // ---- MOTHER's body, as molten rock.
673
1172
  //
@@ -677,7 +1176,7 @@ const ALBEDO_ROWS_PER_FRAME = 12;
677
1176
  // disagree the surface looks like it is moving rather than painted. Every so often something
678
1177
  // bursts inside: a flash, a white core, a ring of fire running out from it and fading.
679
1178
  //
680
- // The map is built once, the way the dwarfs' are, a band at a time; what changes frame to frame
1179
+ // The map is built once, the way the planets' are, a band at a time; what changes frame to frame
681
1180
  // is only where it is read and what is bursting.
682
1181
  const MAGMA_W = 512;
683
1182
  const MAGMA_H = 256;
@@ -732,11 +1231,19 @@ export function magmaMap(rows = MAGMA_H) {
732
1231
  return magmaBuild.done ? map : null;
733
1232
  }
734
1233
 
735
- // Whether the slow textures are whole: MOTHER's crust and the surface of each class of dwarf. They
736
- // are built a band at a time, shared by every scene; a scene painted before they are whole draws
737
- // its bodies the older way, and the Macroverso paints its sprites once more when this turns true.
1234
+ // Whether the slow textures are whole: MOTHER's crust and the surface of each planet. They are built
1235
+ // a band at a time, shared by every scene; a scene painted before they are whole draws its planets
1236
+ // the plainer way, and the Macroverso paints its sprites once more when this turns true.
738
1237
  export function texturesReady() {
739
- return Boolean(magmaBuild.done) && Object.keys(MEMORY_COLORS).every((kind) => kind === COLLAPSED || dwarfAlbedos.get(kind)?.done);
1238
+ return Boolean(magmaBuild.done) && Object.keys(PLANETS).every((kind) => planetMaps.get(kind)?.done);
1239
+ }
1240
+ // One band more of the next planet's surface not yet whole, for whoever paints sprites that do not
1241
+ // draw every frame (the Macroverso): without it a planet no universe on screen has would never be
1242
+ // built, and the sprites painted before would keep the plainer drawing.
1243
+ export function buildPlanets(rows = PLANET_ROWS_PER_FRAME) {
1244
+ const next = Object.keys(PLANETS).find((kind) => !planetMaps.get(kind)?.done);
1245
+ if (next) planetMap(next, rows);
1246
+ return !next;
740
1247
  }
741
1248
 
742
1249
  // The shading. Pure: a table (sphereTable), the map, and the moment in; RGBA out. `turn` is how
@@ -1586,6 +2093,7 @@ export function createNostromo(nostromo) {
1586
2093
  // painted face at its current size.
1587
2094
  const shading = { frame: -1, painted: 0, built: false };
1588
2095
  let magmaSprite = null;
2096
+ let coreSun = null; // the star at the centre (sunOrb), painted at the size it is seen
1589
2097
 
1590
2098
  function beginImplosion(node, t) {
1591
2099
  node.forgetting = { at: t };
@@ -1852,50 +2360,56 @@ export function createNostromo(nostromo) {
1852
2360
  return { phase, beat: pulse(0) + 0.55 * pulse(0.22) };
1853
2361
  }
1854
2362
 
1855
- function dwarfSprite(node, radius, burn, pixels, frame) {
2363
+ // A planet's face, painted into a buffer of its own. `look` is how it is lit now: `light`, the
2364
+ // direction of the sun from it in view space; `exposure`, `fade` and `fill` as shadePlanet reads
2365
+ // them. Painted again once the middle of its face has turned half a pixel, or the light on it
2366
+ // has moved its terminator about a pixel, so a small planet is painted rarely and a large one,
2367
+ // close up, as often as it needs.
2368
+ function planetSprite(node, radius, pixels, frame, look) {
1856
2369
  if (typeof ImageData !== 'function') return null;
1857
2370
  if (shading.frame !== frame) { shading.frame = frame; shading.painted = 0; shading.built = false; }
1858
- const size = Math.max(8, Math.min(200, 2 * Math.round(radius * pixels)));
1859
- const kind = node.memory.kind;
1860
- if (!dwarfAlbedos.get(kind)?.done) {
2371
+ const kind = planetOf(node.memory.kind);
2372
+ const halo = PLANETS[kind].air ? PLANET_HALO : 1;
2373
+ // The disc is never painted wider than 200 pixels, as the stars were; beyond that it is scaled.
2374
+ const size = Math.max(8, Math.min(2 * Math.round(100 * halo), 2 * Math.round(radius * halo * pixels)));
2375
+ if (!planetMaps.get(kind)?.done) {
1861
2376
  if (shading.built) return null;
1862
2377
  shading.built = true;
1863
- if (!dwarfAlbedo(kind, ALBEDO_ROWS_PER_FRAME)) return null;
2378
+ if (!planetMap(kind, PLANET_ROWS_PER_FRAME)) return null;
1864
2379
  }
1865
- const map = dwarfAlbedo(kind);
1866
- const colour = [1, 3, 5].map((at) => Number.parseInt(String(node.color).slice(at, at + 2), 16) / 255);
1867
- if (colour.some((value) => !Number.isFinite(value))) return null;
2380
+ const map = planetMap(kind);
1868
2381
  let sprite = node.sprite;
1869
2382
  // A body that has never been painted at this size waits its turn like any other: when a whole
1870
- // class becomes ready at once it is introduced a few dozen a frame, not all in one.
1871
- if ((!sprite || sprite.size !== size) && shading.painted >= SHADE_BUDGET) return sprite?.canvas ?? null;
1872
- if (!sprite || sprite.size !== size) {
2383
+ // planet becomes ready at once it is introduced a few dozen a frame, not all in one.
2384
+ const anew = !sprite || sprite.size !== size || sprite.kind !== kind;
2385
+ if (anew && shading.painted >= SHADE_BUDGET) return sprite?.kind === kind ? sprite.canvas : null;
2386
+ if (anew) {
1873
2387
  const canvas = document.createElement('canvas');
1874
2388
  canvas.width = size;
1875
2389
  canvas.height = size;
1876
2390
  const paint = canvas.getContext('2d');
1877
2391
  if (!paint?.createImageData) return null;
1878
- sprite = node.sprite = { canvas, paint, image: paint.createImageData(size, size), size, turn: NaN, burn: -1, colour: '', standing: '' };
1879
- }
1880
- const turn = node.spin * 0.3 + node.seed;
1881
- // Painted again once the middle of its face has moved half a pixel, so a small body is painted
1882
- // rarely and a large one, close up, as often as it needs.
1883
- const fresh = !(sprite.turn === sprite.turn);
1884
- const traits = STAR_TRAITS[kind] ?? SUN_TRAITS;
1885
- const standing = `${node.memory.zone ?? 'hold'}${node.cold ? ':cold' : ''}`;
1886
- const moved = fresh
2392
+ sprite = node.sprite = { canvas, paint, image: paint.createImageData(size, size), size, kind, turn: NaN, light: [0, 0, 0], exposure: -1, fade: -1, fill: -1 };
2393
+ }
2394
+ // For whoever asked for stillness a planet does not spin, and its clouds stay where they are;
2395
+ // the light on it still follows the map when they turn it by hand.
2396
+ const turn = (nostromo.reduced ? 0 : node.spin * 0.3) + node.seed;
2397
+ const [lx, ly, lz] = look.light;
2398
+ const moved = !(sprite.turn === sprite.turn)
1887
2399
  || Math.abs(turn - sprite.turn) * size > 1
1888
- || Math.abs(burn - sprite.burn) > 0.04
1889
- || sprite.colour !== node.color
1890
- || sprite.standing !== standing;
2400
+ || Math.hypot(lx - sprite.light[0], ly - sprite.light[1], lz - sprite.light[2]) * size > 2
2401
+ || Math.abs(look.exposure - sprite.exposure) > 0.03
2402
+ || look.fade !== sprite.fade
2403
+ || Math.abs(look.fill - sprite.fill) > 0.04;
1891
2404
  if (moved && shading.painted < SHADE_BUDGET) {
1892
2405
  shading.painted += 1;
1893
- shadeDwarf(sprite.image.data, sphereTable(size), map, { colour, traits, surface: surfaceOf(node.memory, traits, Boolean(node.cold)), turn, burn });
2406
+ shadePlanet(sprite.image.data, globeTable(size, halo), map, { kind, light: look.light, turn, exposure: look.exposure, fade: look.fade, fill: look.fill });
1894
2407
  sprite.paint.putImageData(sprite.image, 0, 0);
1895
2408
  sprite.turn = turn;
1896
- sprite.burn = burn;
1897
- sprite.colour = node.color;
1898
- sprite.standing = standing;
2409
+ sprite.light = [lx, ly, lz];
2410
+ sprite.exposure = look.exposure;
2411
+ sprite.fade = look.fade;
2412
+ sprite.fill = look.fill;
1899
2413
  }
1900
2414
  return sprite.canvas;
1901
2415
  }
@@ -1946,7 +2460,7 @@ export function createNostromo(nostromo) {
1946
2460
  magmaSprite = { canvas, paint, image: paint.createImageData(size, size), size };
1947
2461
  }
1948
2462
  // Painted every other frame: rock this slow, and bursts this short, read the same at half the
1949
- // rate, and the frames between are free for the dwarfs.
2463
+ // rate, and the frames between are free for the planets.
1950
2464
  magmaSprite.frame = (magmaSprite.frame ?? 0) + 1;
1951
2465
  if (magmaSprite.painted && magmaSprite.frame % 2) return magmaSprite.canvas;
1952
2466
  magmaSprite.painted = true;
@@ -2386,385 +2900,152 @@ export function createNostromo(nostromo) {
2386
2900
  // One memory, drawn where the projection put it. Called twice over the list: the ones behind
2387
2901
  // MOTHER before her, so she hides them, and the ones in front after her.
2388
2902
  const drawMemory = (node) => {
2389
- const micro = 1 + 0.05 * Math.sin(t * node.rate + node.seed);
2390
- // Never smaller than a point and a half on screen, while it is there at all.
2391
- const r = node.scale > 0.01 ? Math.max(node.r * node.scale * micro, 1.5 / cam.scale) : 0;
2903
+ // Never smaller than a point and a half on screen, while it is there at all. A planet holds
2904
+ // its size: the breathing the stars had is gone with them (2026-11-15).
2905
+ const r = node.scale > 0.01 ? Math.max(node.r * node.scale, 1.5 / cam.scale) : 0;
2392
2906
  if (r <= 0) return;
2393
2907
  const arrive = Math.min(1.2, node.lit ?? 0);
2394
- // Two things decide how brightly a dwarf burns. Maturity is what the room has made of it
2395
- // over time: how often it has been reached for, how lately, how woven into the rest. Feeding
2396
- // is what it is being given right now, by MOTHER and by its neighbours at once. A young
2397
- // memory nobody feeds is nearly out; an old one the room leans on runs white.
2908
+ // Two things decide how much of its light a memory shows. Maturity is what the room has made
2909
+ // of it over time: how often it has been reached for, how lately, how woven into the rest.
2910
+ // Feeding is what it is being given right now, by MOTHER and by its neighbours at once.
2398
2911
  const grown = node.activity ?? 0;
2399
2912
  const fed = Math.min(1, (node.charge ?? 0) + 0.25 * arrive);
2400
2913
  const burn = Math.min(1, 0.4 * grown + 0.75 * fed);
2401
2914
 
2402
- // A collapsed body. This one is not a star and it is not a furnace either: it is a claim the
2403
- // room established is false, and what it looks like is absence. A round black nothing, the
2404
- // dust and stars of the field standing around it, and the faint cold light of what passes
2405
- // close enough to be bent round the rim instead of going straight.
2406
- //
2407
- // There is no disc and nothing burns. The whole of it is the dark, and the dark is the point.
2915
+ // The aberration is a black hole (drawBlackHole). Seen from far, the disc, the ring and the
2916
+ // field would be smaller than a pixel and only smear into a stain: a small one reads by what
2917
+ // it is, a black point with a thin line of its disc across it and the ring of light round it.
2408
2918
  if (node.memory.kind === COLLAPSED) {
2409
- const hole = r * 1.35;
2410
- const field = hole * 2.4;
2411
- const turn = node.seed + node.spin * 0.12;
2412
- const lit = 0.45 + 0.55 * burn;
2413
-
2414
- // Seen from far, the field of dust and the arcs are smaller than a pixel and only smear
2415
- // into a grey stain round a black blot. A small void reads by what it is: a dark point with
2416
- // one thin cold rim of bent light, its colour the kind's.
2417
- if (hole * cam.scale < 9) {
2418
- ctx.fillStyle = 'rgba(0, 0, 3, .92)';
2419
- ctx.beginPath(); ctx.arc(node.x, node.y, hole, 0, Math.PI * 2); ctx.fill();
2420
- ctx.strokeStyle = hexAlpha(hexMix(node.color, '#a8ccff', 0.55), (0.45 + 0.35 * lit) * glowAt);
2421
- ctx.lineWidth = 1 / cam.scale;
2422
- ctx.beginPath(); ctx.arc(node.x, node.y, hole + 0.6 / cam.scale, 0, Math.PI * 2); ctx.stroke();
2423
- if (node === nostromo.hover && !nostromo.selected) drawSight(ctx, node.x, node.y, hole * 1.6, t, cam.scale);
2919
+ const S = r * 1.15;
2920
+ const lit = (0.6 + 0.4 * burn) * glowAt;
2921
+ const turn = node.seed + (nostromo.reduced ? 0 : node.spin * 0.12);
2922
+ const roll = (frac(node.seed * 0.37) - 0.5) * 0.5;
2923
+ const tone = MEMORY_COLORS.aberration;
2924
+ if (S * cam.scale < 7) {
2925
+ const px = 1 / cam.scale;
2926
+ ctx.save();
2927
+ ctx.translate(node.x, node.y);
2928
+ ctx.rotate(roll);
2929
+ ctx.lineCap = 'round';
2930
+ ctx.strokeStyle = hexAlpha(hexMix(tone, '#ffffff', 0.45), 0.55 * lit);
2931
+ ctx.lineWidth = px;
2932
+ ctx.beginPath(); ctx.ellipse(0, 0, S * 2.2, S * 2.2 * HOLE_TILT, 0, 0, Math.PI * 2); ctx.stroke();
2933
+ ctx.fillStyle = 'rgba(0, 0, 0, 1)';
2934
+ ctx.beginPath(); ctx.arc(0, 0, S, 0, Math.PI * 2); ctx.fill();
2935
+ ctx.strokeStyle = hexAlpha(hexMix(tone, '#ffffff', 0.7), 0.7 * lit);
2936
+ ctx.beginPath(); ctx.arc(0, 0, S + 0.6 * px, 0, Math.PI * 2); ctx.stroke();
2937
+ ctx.strokeStyle = hexAlpha(hexMix(tone, '#ffffff', 0.45), 0.55 * lit);
2938
+ ctx.beginPath(); ctx.ellipse(0, 0, S * 2.2, S * 2.2 * HOLE_TILT, 0, 0, Math.PI); ctx.stroke();
2939
+ ctx.restore();
2940
+ if (node === nostromo.hover && !nostromo.selected) drawSight(ctx, node.x, node.y, S * 1.6, t, cam.scale);
2424
2941
  return;
2425
2942
  }
2426
-
2427
- // The field it sits in: specks of dust and far stars, each on its own slow flicker.
2428
- ctx.globalCompositeOperation = 'lighter';
2429
- for (let i = 0; i < VOID_DUST.length; i += 1) {
2430
- const speck = VOID_DUST[i];
2431
- const at = hole * 1.06 + (field - hole * 1.06) * speck.out;
2432
- const angle = speck.angle + turn;
2433
- const x = node.x + Math.cos(angle) * at;
2434
- const y = node.y + Math.sin(angle) * at;
2435
- // Fading outward, so the field thins into the dark rather than stopping.
2436
- const fade = (1 - speck.out * 0.72) * lit * (0.45 + 0.55 * Math.abs(Math.sin(t * speck.rate + speck.phase)));
2437
- const size = speck.size * (1 + 0.25 * burn) / cam.scale;
2438
- const glow = ctx.createRadialGradient(x, y, 0, x, y, size * 3.2);
2439
- glow.addColorStop(0, `rgba(${speck.colour}, ${fade})`);
2440
- glow.addColorStop(0.35, `rgba(${speck.colour}, ${fade * 0.3})`);
2441
- glow.addColorStop(1, `rgba(${speck.colour}, 0)`);
2442
- ctx.fillStyle = glow;
2443
- ctx.beginPath(); ctx.arc(x, y, size * 3.2, 0, Math.PI * 2); ctx.fill();
2444
- }
2445
- ctx.globalCompositeOperation = 'source-over';
2446
-
2447
- // The void. Black all the way through, with just enough softness at the rim that it reads
2448
- // as depth rather than as a sticker.
2449
- const pit = ctx.createRadialGradient(node.x, node.y, 0, node.x, node.y, hole * 1.1);
2450
- pit.addColorStop(0, 'rgba(0, 0, 0, 1)');
2451
- pit.addColorStop(0.86, 'rgba(0, 0, 0, 1)');
2452
- pit.addColorStop(0.95, 'rgba(0, 0, 2, .82)');
2453
- pit.addColorStop(1, 'rgba(0, 0, 4, 0)');
2454
- ctx.fillStyle = pit;
2455
- ctx.beginPath(); ctx.arc(node.x, node.y, hole * 1.1, 0, Math.PI * 2); ctx.fill();
2456
-
2457
- // What passes close enough is bent round instead of going straight: a cold ring of
2458
- // smeared light gripping the rim, in a few arcs that do not quite close.
2459
- ctx.globalCompositeOperation = 'lighter';
2460
- const halo = ctx.createRadialGradient(node.x, node.y, hole * 0.94, node.x, node.y, hole * 1.3);
2461
- halo.addColorStop(0, 'rgba(150, 190, 255, 0)');
2462
- halo.addColorStop(0.3, `rgba(168, 204, 255, ${0.26 * lit})`);
2463
- halo.addColorStop(0.55, `rgba(120, 160, 230, ${0.12 * lit})`);
2464
- halo.addColorStop(1, 'rgba(90, 130, 210, 0)');
2465
- ctx.fillStyle = halo;
2466
- ctx.beginPath(); ctx.arc(node.x, node.y, hole * 1.3, 0, Math.PI * 2); ctx.fill();
2467
- ctx.lineCap = 'round';
2468
- for (let arc = 0; arc < 4; arc += 1) {
2469
- const at = hole * (1.005 + arc * 0.028);
2470
- const from = turn * (1 + arc * 0.35) + arc * 1.9;
2471
- const span = 0.9 + 0.5 * Math.sin(t * 0.21 + arc);
2472
- ctx.strokeStyle = `rgba(${arc % 2 ? '198, 222, 255' : '146, 186, 250'}, ${(0.3 - 0.05 * arc) * lit})`;
2473
- ctx.lineWidth = (1.4 - 0.25 * arc) / cam.scale;
2474
- ctx.beginPath(); ctx.arc(node.x, node.y, at, from, from + span); ctx.stroke();
2475
- }
2476
- ctx.globalCompositeOperation = 'source-over';
2477
-
2478
- if (node === nostromo.hover && !nostromo.selected) drawSight(ctx, node.x, node.y, field, t, cam.scale);
2943
+ drawBlackHole(ctx, node.x, node.y, S, { t, turn, roll, lit, px: 1 / cam.scale, still: nostromo.reduced, colour: tone, dust: S * cam.scale < 30 ? 28 : VOID_DUST.length });
2944
+ if (node === nostromo.hover && !nostromo.selected) drawSight(ctx, node.x, node.y, S * 2.8, t, cam.scale);
2479
2945
  return;
2480
2946
  }
2481
2947
 
2948
+ // Where the sun is from here, in view space: the light comes from it. The projection keeps
2949
+ // the planet's place on the screen and its depth; undoing the perspective on the first two
2950
+ // gives back the direction in the same space the face is painted in.
2951
+ const depth = node.depth ?? 0;
2952
+ const near = VIEW_DISTANCE / Math.max(200, VIEW_DISTANCE - depth);
2953
+ const vx = node.x / near;
2954
+ const vy = node.y / near;
2955
+ const away = Math.hypot(vx, vy, depth) || 1;
2956
+ const light = [-vx / away, -vy / away, -depth / away];
2957
+ // A memory out of circulation is a faded planet; one the archive has never once carried shows
2958
+ // less of its light; the one being read is lit a little from the front as well, so it never
2959
+ // turns to night when it turns to face you with the sun behind it.
2960
+ const fade = travels(node.memory) ? 0 : 1;
2961
+ const exposure = (1.1 + 0.35 * burn) * (node.cold ? 0.72 : 1);
2962
+ const fill = nostromo.lock?.node === node ? Math.min(1, nostromo.lock.fade ?? 0) : 0;
2963
+ const planet = PLANETS[planetOf(node.memory.kind)];
2964
+ const halo = planet.air ? PLANET_HALO : 1;
2965
+
2482
2966
  // Drawn pixel by pixel wherever there is a buffer to paint into.
2483
- const sprite = dwarfSprite(node, node.r * node.scale, burn, cam.scale * dpr, t);
2484
- if (sprite) ctx.drawImage(sprite, node.x - r, node.y - r, r * 2, r * 2);
2967
+ const sprite = planetSprite(node, node.r * node.scale, cam.scale * dpr, t, { light, exposure, fade, fill });
2968
+ if (sprite) ctx.drawImage(sprite, node.x - r * halo, node.y - r * halo, r * halo * 2, r * halo * 2);
2485
2969
  else {
2970
+ // The plainer way, until its map is built or where there is no buffer: the planet's colour,
2971
+ // brighter toward the sun, and night laid over the far side along the line to it, as deep
2972
+ // as the sphere's own light says at each point of that line.
2973
+ const base = fade ? hexMix(planet.base, '#5c6068', 0.65) : planet.base;
2974
+ const flat = Math.hypot(light[0], light[1]);
2975
+ const ux = flat > 0.04 ? light[0] / flat : 1;
2976
+ const uy = flat > 0.04 ? light[1] / flat : 0;
2486
2977
  ctx.save();
2487
2978
  ctx.beginPath(); ctx.arc(node.x, node.y, r, 0, Math.PI * 2); ctx.closePath();
2488
- // The ground, struck from the body's own middle: a star is not lit from a corner. It runs
2489
- // white at the centre the harder it burns and keeps its class's colour outward.
2490
- const ground = ctx.createRadialGradient(node.x, node.y, r * 0.03, node.x, node.y, r);
2491
- ground.addColorStop(0, hexMix(node.color, '#ffffff', 0.5 + 0.5 * burn));
2492
- ground.addColorStop(0.45, hexMix(node.color, '#ffffff', 0.12 + 0.4 * burn));
2493
- ground.addColorStop(0.85, hexMix(node.color, '#000000', 0.2 - 0.2 * burn));
2494
- ground.addColorStop(1, hexMix(node.color, '#000000', 0.34 - 0.24 * burn));
2495
- ctx.fillStyle = ground;
2979
+ const bright = ctx.createRadialGradient(node.x + ux * r * 0.45 * flat, node.y + uy * r * 0.45 * flat, r * 0.05, node.x, node.y, r * 1.05);
2980
+ bright.addColorStop(0, hexMix(base, '#ffffff', 0.12 + 0.1 * burn));
2981
+ bright.addColorStop(0.55, base);
2982
+ bright.addColorStop(1, hexMix(base, '#000000', 0.35));
2983
+ ctx.fillStyle = bright;
2496
2984
  ctx.fill();
2497
2985
  ctx.clip();
2498
- // The face: the boiling surface a star of this class has, turning slowly, laid over the
2499
- // whole body. This is most of what is seen, so it is laid down at close to full strength.
2500
- const face = dwarfTexture(node.color);
2501
- if (face) {
2502
- // Wrapped on a sphere, half the strip across the visible face, in columns that narrow
2503
- // toward the limb: the cells slide in from one edge, cross wide and leave thin, which is
2504
- // what reads as a body turning rather than a picture sliding behind a hole.
2505
- const strip = face.width / 2;
2506
- const turn = ((node.spin * 0.3 + node.seed) / (Math.PI * 2) % 1 + 1) % 1;
2507
- ctx.globalAlpha = 0.72 + 0.26 * burn;
2508
- for (let column = 0; column < SKIN_COLUMNS; column += 1) {
2509
- const x0 = SKIN_EDGES[column];
2510
- const x1 = SKIN_EDGES[column + 1];
2511
- ctx.drawImage(face, (turn + column / (SKIN_COLUMNS * 2)) * strip, 0, strip / (SKIN_COLUMNS * 2), face.height,
2512
- node.x + x0 * r * 1.06, node.y - r * 1.06, Math.max(0.5, (x1 - x0) * r * 1.06), r * 2.12);
2513
- }
2514
- ctx.globalAlpha = 1;
2986
+ const night = ctx.createLinearGradient(node.x + ux * r, node.y + uy * r, node.x - ux * r, node.y - uy * r);
2987
+ for (let step = 0; step <= 8; step += 1) {
2988
+ const along = 1 - step / 4;
2989
+ const lit = along * flat + Math.sqrt(Math.max(0, 1 - along * along)) * light[2];
2990
+ const dark = (1 - smooth(-0.08, 0.3, lit)) * (node.cold ? 0.96 : 0.93);
2991
+ night.addColorStop(step / 8, `rgba(0, 0, 0, ${dark.toFixed(3)})`);
2515
2992
  }
2516
- // The hottest of it burns through the face, the way an active region does.
2517
- ctx.globalCompositeOperation = 'lighter';
2518
- const core = ctx.createRadialGradient(node.x, node.y, 0, node.x, node.y, r * 0.92);
2519
- core.addColorStop(0, hexAlpha(hexMix(node.color, '#ffffff', 0.9), 0.2 + 0.45 * burn));
2520
- core.addColorStop(0.5, hexAlpha(hexMix(node.color, '#ffffff', 0.5), 0.08 + 0.2 * burn));
2521
- core.addColorStop(1, hexAlpha(node.color, 0));
2522
- ctx.fillStyle = core;
2993
+ ctx.fillStyle = night;
2523
2994
  ctx.fillRect(node.x - r, node.y - r, r * 2, r * 2);
2524
- ctx.globalCompositeOperation = 'source-over';
2525
2995
  ctx.restore();
2526
2996
  }
2527
2997
 
2528
- // A body in space (2026-10-28): the core lights it. The side facing the core takes its light,
2529
- // the far side falls into a soft night, a thin crescent rides the lit limb and a small sheen
2530
- // sits where the light strikes — so even a dwarf a few pixels wide reads as a sphere, not a
2531
- // disc. Its own fire still shows through the night side: it is a star, only a turned one.
2532
- if (r > 1.5) {
2533
- const away = Math.hypot(node.x, node.y) || 1;
2534
- const lx = -node.x / away;
2535
- const ly = -node.y / away;
2536
- ctx.save();
2537
- ctx.beginPath(); ctx.arc(node.x, node.y, r, 0, Math.PI * 2); ctx.clip();
2538
- const night = ctx.createLinearGradient(node.x + lx * r, node.y + ly * r, node.x - lx * r, node.y - ly * r);
2539
- const dark = node.cold ? 0.72 : 0.56;
2540
- night.addColorStop(0, 'rgba(0, 0, 0, 0)');
2541
- night.addColorStop(0.42, 'rgba(0, 0, 0, 0.04)');
2542
- night.addColorStop(0.7, `rgba(0, 0, 0, ${dark * 0.62})`);
2543
- night.addColorStop(1, `rgba(0, 0, 0, ${dark})`);
2544
- ctx.fillStyle = night;
2545
- ctx.fillRect(node.x - r, node.y - r, r * 2, r * 2);
2546
- ctx.globalCompositeOperation = 'lighter';
2547
- const sheen = ctx.createRadialGradient(node.x + lx * r * 0.42, node.y + ly * r * 0.42, 0, node.x + lx * r * 0.42, node.y + ly * r * 0.42, r * 0.62);
2548
- sheen.addColorStop(0, `rgba(255, 255, 255, ${0.26 + 0.12 * burn})`);
2549
- sheen.addColorStop(1, 'rgba(255, 255, 255, 0)');
2550
- ctx.fillStyle = sheen;
2551
- ctx.fillRect(node.x - r, node.y - r, r * 2, r * 2);
2552
- ctx.restore();
2553
- // The crescent on the lit limb: filled between the limb and an ellipse narrowed toward the core,
2554
- // never stroked — a line round a ball flattens it however thin it is.
2555
- ctx.save();
2998
+ // A pulse landing: the planet catches it, a brief light round it in the colour it arrived in.
2999
+ if (arrive > 0.01) {
2556
3000
  ctx.globalCompositeOperation = 'lighter';
2557
- const facing = Math.atan2(ly, lx);
2558
- ctx.fillStyle = hexAlpha(hexMix(node.color, '#ffffff', 0.65), 0.42 * glowAt);
2559
- ctx.beginPath();
2560
- ctx.arc(node.x, node.y, r, facing - 1.15, facing + 1.15);
2561
- ctx.ellipse(node.x, node.y, r * 0.86, r, facing, 1.15, -1.15, true);
2562
- ctx.fill();
2563
- ctx.restore();
3001
+ const air = ctx.createRadialGradient(node.x, node.y, r * 0.99, node.x, node.y, r * 1.38);
3002
+ air.addColorStop(0, hexAlpha(hexMix(node.color, '#ffffff', 0.3), 0.32 * arrive * glowAt));
3003
+ air.addColorStop(0.3, hexAlpha(node.color, 0.12 * arrive * glowAt));
3004
+ air.addColorStop(1, hexAlpha(node.color, 0));
3005
+ ctx.fillStyle = air;
3006
+ ctx.beginPath(); ctx.arc(node.x, node.y, r * 1.34, 0, Math.PI * 2); ctx.fill();
3007
+ ctx.globalCompositeOperation = 'source-over';
2564
3008
  }
2565
3009
 
2566
- // The glow: the light a star gives off, clinging to it in a tight bloom the width of a finger,
2567
- // the same all the way round because nothing else is lighting it. It carries past the body
2568
- // and stops there, so it belongs to the star rather than hanging off it.
2569
- ctx.globalCompositeOperation = 'lighter';
2570
- const air = ctx.createRadialGradient(node.x, node.y, r * 0.99, node.x, node.y, r * 1.42);
2571
- // It starts at the limb, never over it, and no brighter than the limb itself: scattered
2572
- // light falling away from the body, with no seam and no ring. A cooling dwarf gives less of
2573
- // it, in the same proportion its face has dimmed.
2574
- const cooling = node.cold ? COLD_GLOW : 1;
2575
- air.addColorStop(0, hexAlpha(hexMix(node.color, '#ffffff', 0.2 + 0.3 * burn), ((0.16 + 0.34 * burn) * cooling + 0.2 * arrive) * glowAt));
2576
- air.addColorStop(0.25, hexAlpha(hexMix(node.color, '#ffffff', 0.1 + 0.2 * burn), ((0.07 + 0.16 * burn) * cooling + 0.1 * arrive) * glowAt));
2577
- air.addColorStop(1, hexAlpha(node.color, 0));
2578
- ctx.fillStyle = air;
2579
- ctx.beginPath(); ctx.arc(node.x, node.y, r * 1.34, 0, Math.PI * 2); ctx.fill();
2580
- ctx.globalCompositeOperation = 'source-over';
2581
-
2582
3010
  if (node === nostromo.hover && !nostromo.selected) drawSight(ctx, node.x, node.y, r * 1.1, t, cam.scale);
2583
- };
3011
+ };
2584
3012
  const ordered = [...nostromo.nodes].sort((a, b) => (a.depth ?? 0) - (b.depth ?? 0));
2585
3013
  for (const node of ordered) if ((node.depth ?? 0) < 0) drawMemory(node);
2586
3014
 
2587
- // ---- MOTHER's core: a body, not a disc.
2588
- //
2589
- // Everything on the surface lives at a latitude and a longitude and is projected before it
2590
- // is drawn, so it narrows toward the limb and goes round the back as the planet turns.
2591
- // Three cues do the work: features that travel on a real sphere, an edge that darkens into
2592
- // shadow, and one fixed light that decides which side is day. The planet turns; the sun
2593
- // stays where it is.
2594
- // The human's hand turns the star with the body around it: the turn adds to its longitude and
2595
- // the tip to its lean, in the same order the memories are projected in.
3015
+ // ---- MOTHER's core. The human's hand turns the star with the body around it: the turn adds to
3016
+ // its longitude, in the same order the memories are projected in.
2596
3017
  const yaw = nostromo.yaw ?? 0;
2597
- const sinT = Math.sin(CORE_TILT + (nostromo.pitch ?? 0));
2598
- const cosT = Math.cos(CORE_TILT + (nostromo.pitch ?? 0));
2599
3018
  const spin = nostromo.spin ?? 0;
2600
- // A point on the surface: where it lands on screen, how much it faces us, what light it takes.
2601
- const surface = (lat, lon) => {
2602
- const cl = Math.cos(lat);
2603
- const px = cl * Math.sin(lon);
2604
- const py = Math.sin(lat);
2605
- const pz = cl * Math.cos(lon);
2606
- const y = py * cosT - pz * sinT;
2607
- const z = py * sinT + pz * cosT;
2608
- return { x: px, y, z, light: Math.max(0, px * CORE_LIGHT.x + y * CORE_LIGHT.y + z * CORE_LIGHT.z) };
2609
- };
2610
-
2611
- // ---- What the star sits in.
2612
- //
2613
- // No wide halo. A body this size does not need a cloud around it to be felt, and a soft
2614
- // smudge only makes it look smaller. What surrounds it is darkness: one tight, fierce skin of
2615
- // light gripping the limb and falling away almost at once, and beyond that a deep red stain
2616
- // so faint it reads as the dark being lit rather than as anything drawn.
2617
- const stain = ctx.createRadialGradient(0, 0, R, 0, 0, R * 4.6);
2618
- stain.addColorStop(0, `rgba(122, 12, 6, ${0.3 + 0.08 * beat})`);
2619
- stain.addColorStop(0.24, `rgba(88, 6, 6, ${0.14 + 0.04 * beat})`);
2620
- stain.addColorStop(0.62, 'rgba(46, 2, 6, .05)');
2621
- stain.addColorStop(1, 'rgba(20, 0, 4, 0)');
2622
- ctx.fillStyle = stain;
2623
- ctx.beginPath(); ctx.arc(0, 0, R * 4.6, 0, Math.PI * 2); ctx.fill();
2624
-
2625
- // ---- The body: a star, dark and molten.
2626
- //
2627
- // A star makes its own light, so it has no day side, no night side and no highlight struck
2628
- // off it by something else. This one is not a bright disc either: it burns deep, almost
2629
- // black at the limb, and what moves on it is liquid rock. The skin is a strip of boiling
2630
- // cells built once and wrapped round the body; a second pass of the same strip, sliding at a
2631
- // different rate, makes the two disagree, and that disagreement is what reads as flow. Over
2632
- // both, masses of molten matter drift across the face at a walking pace.
2633
- ctx.save();
2634
- ctx.beginPath(); ctx.arc(0, 0, R, 0, Math.PI * 2); ctx.closePath();
2635
- ctx.shadowColor = `rgba(220, 44, 12, ${0.55 + 0.2 * beat})`;
2636
- ctx.shadowBlur = 40 + 26 * beat;
2637
- const body = ctx.createRadialGradient(0, 0, R * 0.05, 0, 0, R);
2638
- body.addColorStop(0, `hsl(${14 + 5 * beat} 100% ${28 + 8 * beat}%)`);
2639
- body.addColorStop(0.58, 'hsl(9 100% 20%)');
2640
- body.addColorStop(1, 'hsl(5 100% 10%)');
2641
- ctx.fillStyle = body;
2642
- ctx.fill();
2643
- ctx.shadowBlur = 0;
2644
- ctx.clip();
2645
-
2646
- // Molten rock, painted pixel by pixel wherever there is a buffer to paint into: plates of
2647
- // crust, cracks running white-hot, lava flowing under them, bursts going off inside.
2648
- const magma = magmaFace(R, cam.scale * dpr, t, { turn: spin - yaw, beat, alarm, reduced: nostromo.reduced, tilt: nostromo.pitch ?? 0 });
2649
- if (magma) ctx.drawImage(magma, -R, -R, R * 2, R * 2);
2650
- else {
2651
- // The skin, wrapped on. Each row of the disc takes the slice of the strip belonging to its
2652
- // latitude, cut into pieces so longitude runs as a sphere's does and the cells narrow toward
2653
- // the limb instead of smearing along it. Turning the star is moving the window along.
2654
- // Someone who asked for stillness gets a star that turns and breathes but does not churn.
2655
- const flowTime = nostromo.reduced ? 0 : t;
2656
- const grain = granuleTexture();
2657
- if (grain) {
2658
- const width = grain.width / 2;
2659
- const wrapAt = (turn, alpha, lift) => {
2660
- ctx.globalAlpha = alpha;
2661
- for (let row = 0; row < GRAIN_ROWS; row += 1) {
2662
- const y0 = -R + (row / GRAIN_ROWS) * 2 * R;
2663
- const y1 = -R + ((row + 1) / GRAIN_ROWS) * 2 * R;
2664
- const mid = (y0 + y1) * 0.5;
2665
- const half = Math.sqrt(Math.max(0, R * R - mid * mid));
2666
- if (half < 0.5) continue;
2667
- const v0 = (((y0 + R) / (2 * R) + lift) % 1 + 1) % 1 * grain.height;
2668
- const dv = Math.max(1, ((y1 - y0) / (2 * R)) * grain.height);
2669
- for (let piece = 0; piece < GRAIN_PIECES; piece += 1) {
2670
- const xA = Math.sin((piece / GRAIN_PIECES - 0.5) * Math.PI) * half;
2671
- const xB = Math.sin(((piece + 1) / GRAIN_PIECES - 0.5) * Math.PI) * half;
2672
- const u = (turn + (piece / GRAIN_PIECES) * 0.5) * width;
2673
- ctx.drawImage(grain, u, Math.min(v0, grain.height - dv), (width * 0.5) / GRAIN_PIECES, dv, xA, y0, Math.max(0.5, xB - xA), Math.max(1, y1 - y0));
2674
- }
2675
- }
2676
- ctx.globalAlpha = 1;
2677
- };
2678
- // Advancing the window carries the skin from right to left, so a turn of the hand to the
2679
- // right carries it back the other way, with the memories.
2680
- const turn = (((spin - yaw) / (Math.PI * 2)) % 1 + 1) % 1;
2681
- wrapAt(turn, 0.95, 0);
2682
- // The same skin again, crawling at its own pace: where the two pull apart the surface
2683
- // churns, and that is the slowness of lava rather than the flicker of fire.
2684
- ctx.globalCompositeOperation = 'lighter';
2685
- wrapAt(((turn * 0.83 + flowTime * 0.0042) % 1 + 1) % 1, 0.32, 0.37);
2686
- ctx.globalCompositeOperation = 'source-over';
2687
- }
2688
3019
 
2689
- // Masses of molten matter riding the surface. They are slow, they are large, and each keeps
2690
- // its own drift, so the face is never the same face twice.
2691
- for (let i = 0; i < CORE_FLOWS.length; i += 1) {
2692
- const flow = CORE_FLOWS[i];
2693
- // The masses ride the same way the skin turns. They used to travel against it, and the two
2694
- // motions cancelled into a surface that churned in place instead of turning.
2695
- const p = surface(flow.lat + 0.1 * Math.sin(flowTime * flow.rate * 0.6 + i), flow.lon - spin * 0.96 + yaw + flowTime * flow.drift);
2696
- if (p.z <= 0.02) continue;
2697
- const swell = 0.62 + 0.38 * Math.sin(flowTime * flow.rate + i * 1.7);
2698
- const fade = Math.min(1, p.z * 2.3) * swell;
2699
- ctx.save();
2700
- ctx.translate(p.x * R, p.y * R);
2701
- ctx.rotate(Math.atan2(p.y, p.x));
2702
- ctx.scale(Math.max(0.05, p.z), 1);
2703
- const molten = ctx.createRadialGradient(0, 0, 0, 0, 0, R * flow.size);
2704
- molten.addColorStop(0, `rgba(255, ${flow.hot ? 214 : 96}, ${flow.hot ? 132 : 30}, ${(flow.hot ? 0.46 : 0.2) * fade})`);
2705
- molten.addColorStop(0.42, `rgba(${flow.hot ? '255, 122, 36' : '176, 34, 10'}, ${(flow.hot ? 0.24 : 0.14) * fade})`);
2706
- molten.addColorStop(1, 'rgba(120, 16, 8, 0)');
2707
- ctx.fillStyle = molten;
2708
- ctx.beginPath(); ctx.arc(0, 0, R * flow.size, 0, Math.PI * 2); ctx.fill();
2709
- ctx.restore();
3020
+ // A scene that has a body of its own at the centre (the Macroverso's sun, 2026-11-10: `noCore`)
3021
+ // draws only what is round it.
3022
+ if (!nostromo.noCore) {
3023
+ // ---- The star: the same sun as the Coordinator's in Home (sunOrb, 2026-11-10, asked by the
3024
+ // author: «the sun in the projects does not look like the Coordinator's»). It turns with the
3025
+ // body round it when the human's hand turns it, and its skin answers when a pulse comes home.
3026
+ const side = Math.min(512, Math.max(SUN_SIDE, 2 ** Math.ceil(Math.log2(Math.max(1, R * 2 * cam.scale * dpr)))));
3027
+ // Some engines refuse a second canvas: then the star is its light alone, with no face.
3028
+ if (coreSun !== false && (!coreSun || coreSun.canvas.width !== side)) { try { coreSun = sunOrb({ side }); } catch { coreSun = false; } }
3029
+ const lit = Math.min(1, nostromo.coreLit ?? 0);
3030
+ if (coreSun) {
3031
+ const hand = spin - yaw;
3032
+ if (t - coreSun.paintedAt >= 1 / 30 || coreSun.paintedAt < 0 || coreSun.hand !== hand) {
3033
+ coreSun.paint((nostromo.reduced ? 0 : t * 0.035) + hand, 1);
3034
+ coreSun.paintedAt = t;
3035
+ coreSun.hand = hand;
3036
+ }
3037
+ drawSun(ctx, 0, 0, R, coreSun, { beat, lit });
3038
+ } else {
3039
+ const face = ctx.createRadialGradient(0, 0, 0, 0, 0, R);
3040
+ face.addColorStop(0, 'rgb(255, 240, 206)');
3041
+ face.addColorStop(0.7, 'rgb(250, 206, 140)');
3042
+ face.addColorStop(1, 'rgb(214, 120, 52)');
3043
+ ctx.fillStyle = face;
3044
+ ctx.beginPath(); ctx.arc(0, 0, R, 0, Math.PI * 2); ctx.fill();
2710
3045
  }
2711
-
2712
- // Limb darkening, hard. Looking at the edge of a star means looking through far more of its
2713
- // own gas, and on a body this dark the edge goes almost to black. This is the whole of the
2714
- // illusion: it is what gives the thing its weight.
2715
- const limb = ctx.createRadialGradient(0, 0, R * 0.34, 0, 0, R);
2716
- limb.addColorStop(0, 'rgba(0, 0, 0, 0)');
2717
- limb.addColorStop(0.58, `rgba(96, 8, 4, ${0.3 - 0.05 * beat})`);
2718
- limb.addColorStop(0.85, `rgba(50, 2, 4, ${0.62 - 0.08 * beat})`);
2719
- limb.addColorStop(1, `rgba(14, 0, 2, ${0.9 - 0.1 * beat})`);
2720
- ctx.fillStyle = limb;
2721
- ctx.fillRect(-R, -R, R * 2, R * 2);
2722
3046
  }
2723
- ctx.restore();
2724
3047
 
2725
- // Prominences: arches of matter torn off the limb, standing up and falling back. Few, large
2726
- // and slow. A star this size does not flicker; it heaves.
2727
- ctx.lineCap = 'round';
2728
- for (let i = 0; i < 4; i += 1) {
2729
- const base = i * 1.5708 + t * 0.05;
2730
- const spread = 0.28 + 0.1 * Math.sin(t * 0.37 + i);
2731
- const lift = R * (0.2 + 0.26 * Math.abs(Math.sin(t * 0.21 + i * 1.7)) + 0.3 * alarm);
2732
- const x0 = Math.cos(base - spread) * R * 0.99, y0 = Math.sin(base - spread) * R * 0.99;
2733
- const x1 = Math.cos(base + spread) * R * 0.99, y1 = Math.sin(base + spread) * R * 0.99;
2734
- const cxp = Math.cos(base) * (R + lift * 2.1), cyp = Math.sin(base) * (R + lift * 2.1);
2735
- // A wide dull body of matter with a thin hot thread running through it.
2736
- ctx.strokeStyle = `rgba(190, 34, 14, ${0.2 + 0.14 * Math.abs(Math.sin(t * 0.6 + i))})`;
2737
- ctx.lineWidth = (5.5 + 3 * beat) / cam.scale;
2738
- ctx.beginPath(); ctx.moveTo(x0, y0); ctx.quadraticCurveTo(cxp, cyp, x1, y1); ctx.stroke();
2739
- ctx.strokeStyle = `rgba(255, ${128 + 70 * beat}, ${64 + 60 * beat}, ${0.3 + 0.28 * Math.abs(Math.sin(t * 0.6 + i))})`;
2740
- ctx.lineWidth = (1.5 + 0.9 * beat) / cam.scale;
2741
- ctx.beginPath(); ctx.moveTo(x0, y0); ctx.quadraticCurveTo(cxp, cyp, x1, y1); ctx.stroke();
2742
- }
2743
-
2744
- // The limb. One fierce skin of light gripping the edge, gone within a fraction of a radius:
2745
- // it is what separates the body from the dark, and it holds the whole shape together. It is
2746
- // also what answers when a pulse comes home.
2747
- const home = Math.min(1, nostromo.coreLit ?? 0);
2748
- const fierce = 0.55 + 0.35 * beat + 0.4 * home;
2749
- ctx.globalCompositeOperation = 'lighter';
2750
- const edge = ctx.createRadialGradient(0, 0, R * 0.9, 0, 0, R * 1.22);
2751
- edge.addColorStop(0, 'rgba(255, 96, 34, 0)');
2752
- edge.addColorStop(0.42, `rgba(255, ${132 + 60 * beat}, 62, ${0.5 * fierce})`);
2753
- edge.addColorStop(0.52, `rgba(255, ${176 + 60 * beat}, ${110 + 60 * beat}, ${0.62 * fierce})`);
2754
- edge.addColorStop(1, 'rgba(210, 40, 16, 0)');
2755
- ctx.fillStyle = edge;
2756
- ctx.beginPath(); ctx.arc(0, 0, R * 1.22, 0, Math.PI * 2); ctx.fill();
2757
- ctx.globalCompositeOperation = 'source-over';
2758
- ctx.strokeStyle = `rgba(255, ${186 + 60 * beat}, ${128 + 80 * beat}, ${Math.min(0.92, 0.7 * fierce)})`;
2759
- ctx.lineWidth = (1.2 + 1.2 * beat + 1.1 * home) / cam.scale;
2760
- ctx.beginPath(); ctx.arc(0, 0, R, 0, Math.PI * 2); ctx.stroke();
2761
-
2762
- // ---- Memories: dwarf stars.
2763
- //
2764
- // A dwarf makes its own light, so none of it is in shadow. Its face boils with granules, it
2765
- // dims toward the limb the way every star does, and what light escapes clings to it in a tight
2766
- // bloom the width of a finger. On top of that each breathes at a rate of its own: a
2767
- // micro-pulsation, small enough that it is never a flash and never in time with its neighbours.
3048
+ // ---- Memories: planets, lit by the sun they go round (drawMemory above, PLANETS).
2768
3049
  for (const node of ordered) if ((node.depth ?? 0) >= 0) drawMemory(node);
2769
3050
  // The cold zone, when it is asked for: a thin dusty ring around every memory the archive has
2770
3051
  // had its chances with and never once carried. The mark is added rather than taken from the
@@ -3253,6 +3534,6 @@ export function createNostromo(nostromo) {
3253
3534
 
3254
3535
  return {
3255
3536
  buildNodes, sizeNostromo, placeNostromo, stepNostromo, focusNostromo, projectNostromo, fitNostromo, drawNostromo, drawNebula, heartbeat, setNeural,
3256
- toScreen, toWorld, nostromoLive, nostromoAt, beginImplosion, drawImplosion, drawDust, drawSight, dwarfSprite, magmaFace,
3537
+ toScreen, toWorld, nostromoLive, nostromoAt, beginImplosion, drawImplosion, drawDust, drawSight, planetSprite, magmaFace,
3257
3538
  };
3258
3539
  }