@jossuealcala/madre 1.0.4 → 1.1.0
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.
- package/ADDITIONAL-TERMS.md +7 -2
- package/CHANGELOG.en.md +152 -1
- package/CHANGELOG.md +152 -1
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +111 -661
- package/NOTICE +59 -24
- package/README.en.md +36 -204
- package/README.md +36 -210
- package/SECURITY.md +1 -0
- package/TRADEMARKS.en.md +13 -14
- package/TRADEMARKS.md +42 -26
- package/bin/madre.cjs +2 -2
- package/bin/madre.mjs +114 -42
- package/docs/REFERENCE.md +53 -6
- package/docs/SDK.md +44 -5
- package/docs/en/REFERENCE.md +53 -6
- package/docs/en/SDK.md +43 -4
- package/docs/madre-banner.png +0 -0
- package/docs/sdk/hello-module.mjs +3 -0
- package/package.json +3 -2
- package/public/abduction.js +6 -6
- package/public/activity.js +425 -0
- package/public/app.js +3519 -647
- package/public/assets/abduction-cat-blink.webp +0 -0
- package/public/assets/abduction-cat-control-left.webp +0 -0
- package/public/assets/abduction-cat-control-right.webp +0 -0
- package/public/assets/abduction-cat.webp +0 -0
- package/public/assets/manual/shots/en-agents.webp +0 -0
- package/public/assets/manual/shots/en-chats.webp +0 -0
- package/public/assets/manual/shots/en-code.webp +0 -0
- package/public/assets/manual/shots/en-composer.webp +0 -0
- package/public/assets/manual/shots/en-connectors.webp +0 -0
- package/public/assets/manual/shots/en-continuity.webp +0 -0
- package/public/assets/manual/shots/en-coordinator.webp +0 -0
- package/public/assets/manual/shots/en-copilot.webp +0 -0
- package/public/assets/manual/shots/en-diagnostics.webp +0 -0
- package/public/assets/manual/shots/en-home.webp +0 -0
- package/public/assets/manual/shots/en-local.webp +0 -0
- package/public/assets/manual/shots/en-market.webp +0 -0
- package/public/assets/manual/shots/en-memory.webp +0 -0
- package/public/assets/manual/shots/en-modes.webp +0 -0
- package/public/assets/manual/shots/en-notes.webp +0 -0
- package/public/assets/manual/shots/en-settings.webp +0 -0
- package/public/assets/manual/shots/en-welcome.webp +0 -0
- package/public/assets/manual/shots/en-windows.webp +0 -0
- package/public/assets/manual/shots/es-agents.webp +0 -0
- package/public/assets/manual/shots/es-chats.webp +0 -0
- package/public/assets/manual/shots/es-code.webp +0 -0
- package/public/assets/manual/shots/es-composer.webp +0 -0
- package/public/assets/manual/shots/es-connectors.webp +0 -0
- package/public/assets/manual/shots/es-continuity.webp +0 -0
- package/public/assets/manual/shots/es-coordinator.webp +0 -0
- package/public/assets/manual/shots/es-copilot.webp +0 -0
- package/public/assets/manual/shots/es-diagnostics.webp +0 -0
- package/public/assets/manual/shots/es-home.webp +0 -0
- package/public/assets/manual/shots/es-local.webp +0 -0
- package/public/assets/manual/shots/es-market.webp +0 -0
- package/public/assets/manual/shots/es-memory.webp +0 -0
- package/public/assets/manual/shots/es-modes.webp +0 -0
- package/public/assets/manual/shots/es-notes.webp +0 -0
- package/public/assets/manual/shots/es-settings.webp +0 -0
- package/public/assets/manual/shots/es-welcome.webp +0 -0
- package/public/assets/manual/shots/es-windows.webp +0 -0
- package/public/assets/news/1.1/en/chats.webp +0 -0
- package/public/assets/news/1.1/en/home.webp +0 -0
- package/public/assets/news/1.1/en/maps.webp +0 -0
- package/public/assets/news/1.1/en/market.webp +0 -0
- package/public/assets/news/1.1/en/permissions.webp +0 -0
- package/public/assets/news/1.1/en/privacy.webp +0 -0
- package/public/assets/news/1.1/en/welcome.webp +0 -0
- package/public/assets/news/1.1/es/chats.webp +0 -0
- package/public/assets/news/1.1/es/home.webp +0 -0
- package/public/assets/news/1.1/es/maps.webp +0 -0
- package/public/assets/news/1.1/es/market.webp +0 -0
- package/public/assets/news/1.1/es/permissions.webp +0 -0
- package/public/assets/news/1.1/es/privacy.webp +0 -0
- package/public/assets/news/1.1/es/welcome.webp +0 -0
- package/public/attribution.js +15 -16
- package/public/brands.js +2 -2
- package/public/code-tools.js +2 -2
- package/public/editor.js +13 -13
- package/public/en.js +483 -0
- package/public/es.js +1817 -598
- package/public/hardware.js +2 -2
- package/public/i18n.js +47 -9
- package/public/icons.js +158 -0
- package/public/index.html +68 -51
- package/public/inquiry.js +2 -2
- package/public/loader.js +271 -2
- package/public/macroverso.js +60 -21
- package/public/manual-content.js +900 -0
- package/public/manual-shots.js +47 -0
- package/public/manual.css +246 -0
- package/public/manual.html +15 -0
- package/public/manual.js +427 -0
- package/public/market-art.js +99 -41
- package/public/market-view.js +243 -47
- package/public/market.js +139 -26
- package/public/mcp-catalog.js +62 -0
- package/public/neural.js +64 -8
- package/public/nostromo-engine.js +709 -40
- package/public/page-errors.js +29 -0
- package/public/power.js +350 -11
- package/public/remedy.js +89 -0
- package/public/resay.js +4 -2
- package/public/review-ask.js +12 -7
- package/public/routing.js +3 -3
- package/public/salas-mac.css +875 -48
- package/public/salas-mac.html +27 -15
- package/public/salas-mac.js +1668 -338
- package/public/salas.css +2 -2
- package/public/salas.html +3 -3
- package/public/salas.js +3 -3
- package/public/styles.css +2694 -323
- package/public/syntax.js +2 -2
- package/public/terms.js +152 -0
- package/public/touch.js +2 -2
- package/public/tour-chapters.js +100 -92
- package/public/tour.js +118 -28
- package/public/troubleshooting.js +327 -21
- package/public/wallpaper.js +4 -3
- package/public/welcome.js +923 -0
- package/src/activity.mjs +85 -0
- package/src/adapters/claude.mjs +61 -35
- package/src/adapters/codex.mjs +18 -5
- package/src/adapters/cursor.mjs +60 -9
- package/src/adapters/gemini.mjs +17 -4
- package/src/adapters/madre.mjs +30 -9
- package/src/adapters/opencode.mjs +73 -10
- package/src/adapters/process.mjs +19 -15
- package/src/adapters/subagents.mjs +159 -0
- package/src/asking.mjs +8 -2
- package/src/auth-probe.mjs +47 -11
- package/src/bridge/devices.mjs +2 -2
- package/src/bridge/handoff.mjs +2 -2
- package/src/bridge/host.mjs +2 -2
- package/src/bridge/network.mjs +2 -2
- package/src/bridge/policy.mjs +3 -3
- package/src/bridge/qr.mjs +2 -2
- package/src/bridge/server.mjs +3 -3
- package/src/builtin-updates.mjs +87 -0
- package/src/capabilities.mjs +5 -5
- package/src/chats.mjs +51 -2
- package/src/checkpoint.mjs +67 -9
- package/src/choices.mjs +2 -2
- package/src/cli-args.mjs +2 -2
- package/src/cold.mjs +2 -2
- package/src/commands.mjs +2 -2
- package/src/config.mjs +2 -2
- package/src/conversation-context.mjs +2 -2
- package/src/credentials.mjs +80 -18
- package/src/dataset.mjs +2 -2
- package/src/directives.mjs +2 -2
- package/src/distiller.mjs +2 -2
- package/src/embeddings.mjs +2 -2
- package/src/enlaces.mjs +2 -2
- package/src/environment.mjs +147 -0
- package/src/event-store.mjs +2 -2
- package/src/exam.mjs +2 -2
- package/src/extensions.mjs +2 -2
- package/src/eyecat-watch.mjs +2 -2
- package/src/eyecat.mjs +2 -2
- package/src/file-ops.mjs +2 -2
- package/src/files.mjs +2 -2
- package/src/github.mjs +2 -2
- package/src/heartbeat.mjs +2 -2
- package/src/history.mjs +76 -0
- package/src/i18n.mjs +32 -3
- package/src/image-studio.mjs +2 -2
- package/src/install-metrics.mjs +109 -0
- package/src/json-file.mjs +2 -2
- package/src/launch.mjs +2 -2
- package/src/lease.mjs +15 -4
- package/src/lobby-work.mjs +11 -4
- package/src/local-ai.mjs +12 -4
- package/src/looks.mjs +19 -7
- package/src/market-check.mjs +165 -0
- package/src/market-key.mjs +10 -2
- package/src/market-license.mjs +104 -0
- package/src/market-remote.mjs +71 -13
- package/src/maturity.mjs +2 -2
- package/src/mcp/connect.mjs +2 -2
- package/src/mcp/github-server.mjs +2 -2
- package/src/mcp/image-server.mjs +2 -2
- package/src/mcp/memory-server.mjs +2 -2
- package/src/mcp/proxy.mjs +16 -5
- package/src/mcp/smtp-server.mjs +2 -2
- package/src/memory-dashboard.mjs +2 -2
- package/src/memory-tools.mjs +2 -2
- package/src/memory.mjs +2 -2
- package/src/models.mjs +115 -12
- package/src/module-scope.mjs +2 -2
- package/src/modules/ahp.mjs +2 -2
- package/src/modules/ash-policy.mjs +2 -2
- package/src/modules/ash.mjs +2 -2
- package/src/modules/bishop-exam.mjs +2 -2
- package/src/modules/bishop-plan.mjs +2 -2
- package/src/modules/bishop.mjs +9 -3
- package/src/modules/choices.mjs +2 -2
- package/src/modules/correo.mjs +2 -2
- package/src/modules/enlaces.mjs +2 -2
- package/src/modules/git-pulse.mjs +2 -2
- package/src/modules/github.mjs +2 -2
- package/src/modules/helpers.mjs +2 -2
- package/src/modules/image-studio.mjs +2 -2
- package/src/modules/index.mjs +92 -5
- package/src/modules/intents-calibration.mjs +2 -2
- package/src/modules/intents-desk.mjs +4 -3
- package/src/modules/intents-observe.mjs +2 -2
- package/src/modules/intents-policy.mjs +2 -2
- package/src/modules/intents-try.mjs +2 -2
- package/src/modules/intents.mjs +2 -2
- package/src/modules/local-models.mjs +41 -10
- package/src/modules/mcp-connect.mjs +2 -2
- package/src/modules/notes.mjs +281 -0
- package/src/modules/ollama.mjs +48 -13
- package/src/modules/playwright.mjs +16 -5
- package/src/modules/reminders.mjs +664 -0
- package/src/modules/ripley.mjs +3 -3
- package/src/modules/runs.mjs +2 -2
- package/src/modules/sdk.mjs +57 -9
- package/src/modules/updates.mjs +2 -2
- package/src/mother.mjs +13 -3
- package/src/npm-launch.mjs +2 -2
- package/src/ollama.mjs +8 -6
- package/src/opencode-health.mjs +83 -0
- package/src/outbound.mjs +35 -3
- package/src/override.mjs +27 -22
- package/src/ports.mjs +2 -2
- package/src/prices.mjs +2 -2
- package/src/privacy.mjs +2 -2
- package/src/quota-monitor.mjs +2 -2
- package/src/quota-sources.mjs +2 -2
- package/src/request-guard.mjs +2 -2
- package/src/review-ask.mjs +4 -3
- package/src/room/archivist.mjs +2 -2
- package/src/room/attachments.mjs +2 -2
- package/src/room/budget.mjs +2 -2
- package/src/room/context.mjs +2 -2
- package/src/room/control.mjs +2 -2
- package/src/room/copilot.mjs +2 -2
- package/src/room/economy.mjs +2 -2
- package/src/room/escalation.mjs +2 -2
- package/src/room/ghost.mjs +2 -2
- package/src/room/guard.mjs +6 -4
- package/src/room/prompt.mjs +3 -3
- package/src/room/returns.mjs +2 -2
- package/src/room/runs.mjs +6 -4
- package/src/room/vectors.mjs +2 -2
- package/src/room.mjs +144 -36
- package/src/router.mjs +2 -2
- package/src/runs.mjs +2 -2
- package/src/runtime-detection.mjs +36 -6
- package/src/salas.mjs +31 -6
- package/src/sentinel-errors.mjs +17 -7
- package/src/server-sentinel.mjs +2 -2
- package/src/server.mjs +980 -139
- package/src/setup-trouble.mjs +33 -0
- package/src/setup.mjs +4 -4
- package/src/smtp.mjs +2 -2
- package/src/telemetry.mjs +266 -0
- package/src/terms.mjs +43 -0
- package/src/tour.mjs +60 -7
- package/src/uninstall.mjs +225 -0
- package/src/updates.mjs +2 -2
- package/src/usage-sentinel.mjs +2 -2
- package/src/vault.mjs +2 -2
- package/src/verdict.mjs +13 -10
- package/src/whats-new.mjs +97 -3
- package/public/assets/abduction-cat-blink.png +0 -0
- package/public/assets/abduction-cat-control-left.png +0 -0
- package/public/assets/abduction-cat-control-right.png +0 -0
- package/public/assets/abduction-cat.png +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// NOSTROMO's engine: the physics and the painters of the archive as a body in space, lifted out
|
|
4
4
|
// of the room's page so the Macroverso can draw every room the way its own NOSTROMO is drawn —
|
|
5
5
|
// with these very functions, not a copy of them (docs/MACROVERSO.md, phase 3a).
|
|
@@ -49,6 +49,25 @@ export const VOID_DUST = Array.from({ length: 64 }, (_, i) => {
|
|
|
49
49
|
|
|
50
50
|
// How alive a memory is: how often the room has actually recalled it, how recently, and how
|
|
51
51
|
// woven it is into the rest.
|
|
52
|
+
// HOW MUCH A MEMORY KNOWS (2026-10-28): the more it holds, the bigger its planet or its neuron. What
|
|
53
|
+
// it says (its words, or their count from a far room), the sources it cites and how much of the
|
|
54
|
+
// conversation it distils. Read against the richest memory of the same archive, so the difference
|
|
55
|
+
// shows in a young archive and in an old one; a floor keeps a small archive from drawing giants, and
|
|
56
|
+
// the biggest stays the size the map always allowed (no body so big it looks wrong).
|
|
57
|
+
export function knowledgeOf(memory) {
|
|
58
|
+
const words = Number.isFinite(memory?.words) ? memory.words : (typeof memory?.text === 'string' ? (memory.text.match(/\S+/g) ?? []).length : 0);
|
|
59
|
+
const span = Math.max(1, (memory?.throughSequence ?? 0) - (memory?.fromSequence ?? 0));
|
|
60
|
+
const cited = memory?.sources?.length ?? memory?.sourcesCount ?? 0;
|
|
61
|
+
// A far room sends how many sources a memory cites, not the list of them.
|
|
62
|
+
return Math.log2(1 + words / 12) + 0.8 * Math.log2(1 + span) + 0.6 * Math.min(cited, 8);
|
|
63
|
+
}
|
|
64
|
+
export const BODY_SMALL = 5.5;
|
|
65
|
+
export const BODY_BIG = 18;
|
|
66
|
+
export function bodyOf(known, richest) {
|
|
67
|
+
const share = Math.min(1, known / Math.max(richest, 6));
|
|
68
|
+
return BODY_SMALL + (BODY_BIG - BODY_SMALL) * share ** 0.85;
|
|
69
|
+
}
|
|
70
|
+
|
|
52
71
|
export function rawActivity(memory, degree = 0) {
|
|
53
72
|
const use = 1 - Math.exp(-Number(memory.recalled ?? 0) / 4);
|
|
54
73
|
const since = memory.lastRecalled ? (Date.now() - Date.parse(memory.lastRecalled)) / 86400000 : null;
|
|
@@ -115,7 +134,14 @@ const FISSURE = 0.07;
|
|
|
115
134
|
// sends pulses or answers a click keeps working on the screen it always worked on.
|
|
116
135
|
const BRAIN_WIDTH = 0.84; // ear to ear, against front to back
|
|
117
136
|
const VIEW_DISTANCE = 1500; // world units from the eye to MOTHER: enough to read depth, not to distort
|
|
118
|
-
export const PITCH_LIMIT = 1.1; //
|
|
137
|
+
export const PITCH_LIMIT = 1.1; // how far a held memory tips the head to face you
|
|
138
|
+
// Your hand turns it any way (2026-10-27): over the top and under, all the way round. Past the
|
|
139
|
+
// pole the body is upside down, so a sideways drag turns it the other way to keep following the hand.
|
|
140
|
+
export const turnBy = (yaw, pitch, dx, dy) => {
|
|
141
|
+
const upright = Math.cos(pitch) >= 0 ? 1 : -1;
|
|
142
|
+
const next = pitch + dy * TURN_PER_PIXEL;
|
|
143
|
+
return { yaw: yaw + dx * TURN_PER_PIXEL * upright, pitch: Math.atan2(Math.sin(next), Math.cos(next)) };
|
|
144
|
+
};
|
|
119
145
|
export const TURN_PER_PIXEL = 0.008;
|
|
120
146
|
const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
|
|
121
147
|
// How deep under the surface a memory sits. Thin, on purpose: a thick shell fills the outline in
|
|
@@ -930,6 +956,474 @@ export function neuronGlow(hex) {
|
|
|
930
956
|
NEURON_GLOWS.set(hex, canvas);
|
|
931
957
|
return canvas;
|
|
932
958
|
}
|
|
959
|
+
// A NEURON, after the photographs (2026-10-27, second pass): a cell body with volume, lit from
|
|
960
|
+
// above and to the left, its nucleus showing through; dendrites that leave it thick and branch,
|
|
961
|
+
// tapering, into a tree; one axon wrapped in a beaded sheath that ends in a few terminals, a warm
|
|
962
|
+
// spark at some tips. Every fibre is a tube: a dark edge, its colour, a highlight on the side the
|
|
963
|
+
// light comes from. Drawn once per colour and shape and stamped; the light never turns, so the
|
|
964
|
+
// cells are not turned either, and six shapes keep them from repeating.
|
|
965
|
+
const NEURON_SPRITES = new Map();
|
|
966
|
+
export const NEURON_SPRITE = 224; // the sprite's side; the soma's radius is a twelfth of it
|
|
967
|
+
export const NEURON_SHAPES = 6;
|
|
968
|
+
const NEURON_LIGHT = { x: -0.6, y: -0.8 }; // where the light comes from, the same for every cell
|
|
969
|
+
const NEURON_SPARK = '#ffb45c'; // the warm spark at a synapse, as in the photographs
|
|
970
|
+
// The shape of one neuron, as segments: where it is, how wide at each end, and which are the axon.
|
|
971
|
+
export function neuronSkeleton(rnd, c, r, reach, { depth = 3, thin = 0.4, trunks = 4 + Math.floor(rnd() * 3) } = {}) {
|
|
972
|
+
const segs = [];
|
|
973
|
+
const tips = [];
|
|
974
|
+
const knots = [];
|
|
975
|
+
// The rig (2026-10-28): each trunk is a piece, and each branch that leaves a trunk is a piece hung
|
|
976
|
+
// from it, so the drawing can sway them on their roots (neuronRig, drawNeuronRig). `part` says
|
|
977
|
+
// which piece a fibre, a fork or a tip belongs to; the shapes are the same as without it.
|
|
978
|
+
const parts = [];
|
|
979
|
+
const axon = rnd() * Math.PI * 2;
|
|
980
|
+
// `z` is how near the branch stands: one further back is thinner and fainter, which is most of
|
|
981
|
+
// what makes the cell read as a body in space rather than a drawing on the page.
|
|
982
|
+
const grow = (x, y, a, w, length, level, z = 1, part = -1, rig = 0) => {
|
|
983
|
+
const steps = 8;
|
|
984
|
+
const bend = (rnd() - 0.5) * 0.2;
|
|
985
|
+
for (let step = 0; step < steps; step += 1) {
|
|
986
|
+
a += bend + (rnd() - 0.5) * 0.46;
|
|
987
|
+
const nx = x + Math.cos(a) * (length / steps), ny = y + Math.sin(a) * (length / steps);
|
|
988
|
+
const w1 = Math.max(thin, w * (1 - 0.4 * ((step + 1) / steps)));
|
|
989
|
+
// Now and then the fibre swells a little, the beads a living dendrite carries.
|
|
990
|
+
const bead = step > 1 && step < steps - 1 && rnd() < 0.09;
|
|
991
|
+
segs.push({ x0: x, y0: y, x1: nx, y1: ny, w0: Math.max(thin, w * (1 - 0.4 * (step / steps))), w1, sheath: false, z, bead, part });
|
|
992
|
+
x = nx; y = ny;
|
|
993
|
+
}
|
|
994
|
+
w = Math.max(thin, w * 0.6);
|
|
995
|
+
if (level <= 0 || w <= thin) { tips.push({ x, y, spark: rnd() < 0.3, z, part }); return; }
|
|
996
|
+
// Where it forks the fibre pools a little, as a fluid does at a joint: the web between branches.
|
|
997
|
+
knots.push({ x, y, w: w * 1.5, z, part });
|
|
998
|
+
const kids = rnd() < 0.3 ? 3 : 2;
|
|
999
|
+
for (let k = 0; k < kids; k += 1) {
|
|
1000
|
+
// A branch leaving a trunk is a piece of its own, hung where it leaves.
|
|
1001
|
+
const own = rig === 0 && part >= 0 ? parts.push({ x, y, parent: part, kind: 'branch' }) - 1 : part;
|
|
1002
|
+
grow(x, y, a + (k - (kids - 1) / 2) * (0.5 + rnd() * 0.45), w, length * (0.62 + rnd() * 0.2), level - 1, Math.max(0.45, z - rnd() * 0.18), own, rig + 1);
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
const roots = [];
|
|
1006
|
+
for (let i = 0; i < trunks; i += 1) {
|
|
1007
|
+
const a = axon + 0.7 + ((i + 0.2 + rnd() * 0.6) / trunks) * (Math.PI * 2 - 1.4);
|
|
1008
|
+
roots.push(a);
|
|
1009
|
+
const z = 0.6 + rnd() * 0.4;
|
|
1010
|
+
const x0 = c + Math.cos(a) * r * 0.5, y0 = c + Math.sin(a) * r * 0.5;
|
|
1011
|
+
const trunk = parts.push({ x: x0, y: y0, parent: -1, kind: 'trunk' }) - 1;
|
|
1012
|
+
grow(x0, y0, a, r * (0.32 + 0.22 * z), reach * (0.26 + rnd() * 0.1), depth, z, trunk, 0);
|
|
1013
|
+
}
|
|
1014
|
+
// The axon: long, nearly straight, sheathed, then a few short terminals.
|
|
1015
|
+
let x = c + Math.cos(axon) * r * 0.6, y = c + Math.sin(axon) * r * 0.6, a = axon;
|
|
1016
|
+
const axonPart = parts.push({ x, y, parent: -1, kind: 'axon' }) - 1;
|
|
1017
|
+
const steps = 12;
|
|
1018
|
+
const length = reach * 0.78;
|
|
1019
|
+
for (let step = 0; step < steps; step += 1) {
|
|
1020
|
+
a += (rnd() - 0.5) * 0.14;
|
|
1021
|
+
const nx = x + Math.cos(a) * (length / steps), ny = y + Math.sin(a) * (length / steps);
|
|
1022
|
+
const w0 = step === 0 ? r * 0.42 : r * 0.24, w1 = r * 0.24;
|
|
1023
|
+
segs.push({ x0: x, y0: y, x1: nx, y1: ny, w0, w1, sheath: step > 0 && step < steps - 1, z: 1, part: axonPart });
|
|
1024
|
+
x = nx; y = ny;
|
|
1025
|
+
}
|
|
1026
|
+
for (let k = 0; k < 3; k += 1) grow(x, y, a + (k - 1) * 0.6, r * 0.12, reach * 0.14, 0, 1, axonPart, 2);
|
|
1027
|
+
roots.push(axon);
|
|
1028
|
+
return { c, r, segs, tips, knots, roots, axon, parts };
|
|
1029
|
+
}
|
|
1030
|
+
// The cell body's outline: round, swelling where its trunks leave and toward its axon.
|
|
1031
|
+
function somaPath(paint, sk, scale = 1) {
|
|
1032
|
+
const { c, r } = sk;
|
|
1033
|
+
paint.beginPath();
|
|
1034
|
+
for (let i = 0; i <= 48; i += 1) {
|
|
1035
|
+
const th = (i / 48) * Math.PI * 2;
|
|
1036
|
+
let k = 1;
|
|
1037
|
+
for (const root of sk.roots) k += 0.38 * Math.max(0, Math.cos(th - root)) ** 6;
|
|
1038
|
+
const x = c + Math.cos(th) * r * k * scale, y = c + Math.sin(th) * r * k * scale;
|
|
1039
|
+
if (i) paint.lineTo(x, y); else paint.moveTo(x, y);
|
|
1040
|
+
}
|
|
1041
|
+
paint.closePath();
|
|
1042
|
+
}
|
|
1043
|
+
// One fibre as a tube, in passes so each lies over the last: a glow round it, a dark edge, its
|
|
1044
|
+
// colour, and a highlight on the side the light comes from. Each pass is laid down solid on a layer
|
|
1045
|
+
// and the layer goes on at the pass's strength, so a fibre is one continuous piece of gel: no
|
|
1046
|
+
// seams where its pieces overlap, and two branches crossing merge instead of doubling. A branch
|
|
1047
|
+
// further back is the colour sunk toward the dark rather than see-through.
|
|
1048
|
+
let neuronLayer = null;
|
|
1049
|
+
function tubePass(paint, sk, colour, alpha, widen, toward = 0, add = 0) {
|
|
1050
|
+
const size = paint.canvas;
|
|
1051
|
+
neuronLayer ??= document.createElement('canvas');
|
|
1052
|
+
if (neuronLayer.width !== size.width || neuronLayer.height !== size.height) { neuronLayer.width = size.width; neuronLayer.height = size.height; }
|
|
1053
|
+
const layer = neuronLayer.getContext('2d');
|
|
1054
|
+
layer.setTransform(1, 0, 0, 1, 0, 0);
|
|
1055
|
+
layer.clearRect(0, 0, size.width, size.height);
|
|
1056
|
+
layer.setTransform(paint.getTransform());
|
|
1057
|
+
layer.lineCap = 'round';
|
|
1058
|
+
const sunk = (z) => hexMix(colour, '#050a14', (1 - z) * 0.55);
|
|
1059
|
+
for (const seg of sk.segs) {
|
|
1060
|
+
const dx = seg.x1 - seg.x0, dy = seg.y1 - seg.y0;
|
|
1061
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
1062
|
+
let nx = -dy / d, ny = dx / d;
|
|
1063
|
+
if (nx * NEURON_LIGHT.x + ny * NEURON_LIGHT.y < 0) { nx = -nx; ny = -ny; }
|
|
1064
|
+
const w = (seg.w0 + seg.w1) / 2 * (seg.sheath ? 1.25 : seg.bead ? 1.7 : 1);
|
|
1065
|
+
const off = toward * w;
|
|
1066
|
+
layer.strokeStyle = sunk(seg.z);
|
|
1067
|
+
layer.lineWidth = Math.max(0.35, w * widen + add);
|
|
1068
|
+
layer.beginPath();
|
|
1069
|
+
layer.moveTo(seg.x0 + nx * off, seg.y0 + ny * off);
|
|
1070
|
+
layer.lineTo(seg.x1 + nx * off, seg.y1 + ny * off);
|
|
1071
|
+
layer.stroke();
|
|
1072
|
+
}
|
|
1073
|
+
for (const knot of sk.knots ?? []) {
|
|
1074
|
+
layer.fillStyle = sunk(knot.z);
|
|
1075
|
+
layer.beginPath();
|
|
1076
|
+
layer.arc(knot.x + NEURON_LIGHT.x * toward * knot.w, knot.y + NEURON_LIGHT.y * toward * knot.w, Math.max(0.35, knot.w * widen + add) / 2, 0, Math.PI * 2);
|
|
1077
|
+
layer.fill();
|
|
1078
|
+
}
|
|
1079
|
+
paint.save();
|
|
1080
|
+
paint.setTransform(1, 0, 0, 1, 0, 0);
|
|
1081
|
+
paint.globalAlpha = alpha;
|
|
1082
|
+
paint.drawImage(neuronLayer, 0, 0);
|
|
1083
|
+
paint.restore();
|
|
1084
|
+
}
|
|
1085
|
+
// A living neuron. `life` runs from a cell going out (grey, no glow, no sparks) to one the room
|
|
1086
|
+
// leans on (its colour, its halo, its sparks). Its body and its fibres can be drawn apart (`body`,
|
|
1087
|
+
// `fibres`), so the rig lays each piece on a sheet of its own (neuronRig).
|
|
1088
|
+
// Its texture, after the photographs (2026-10-28): a membrane you half see through, spines along
|
|
1089
|
+
// the thin dendrites, vesicles caught in the light, and the body grained with what fills it.
|
|
1090
|
+
const cellGrain = (x, y, k = 0) => (((Math.sin(x * 12.9898 + y * 78.233 + k * 37.719) * 43758.5453) % 1) + 1) % 1;
|
|
1091
|
+
export function drawLivingNeuron(paint, sk, hex, life = 1, { body = true, fibres = true } = {}) {
|
|
1092
|
+
const tone = hexMix(hex, '#3b4250', (1 - life) * 0.72);
|
|
1093
|
+
const pale = hexMix(tone, '#ffffff', 0.55);
|
|
1094
|
+
const deep = hexMix(tone, '#050a14', 0.62);
|
|
1095
|
+
paint.lineCap = 'round';
|
|
1096
|
+
paint.lineJoin = 'round';
|
|
1097
|
+
paint.globalCompositeOperation = 'lighter';
|
|
1098
|
+
// A faint haze round the fibres and the body, no more: the cell is the subject, not its light.
|
|
1099
|
+
if (fibres) tubePass(paint, sk, tone, 0.03 * life, 2.6, 0, 1);
|
|
1100
|
+
if (body) {
|
|
1101
|
+
const halo = paint.createRadialGradient(sk.c, sk.c, sk.r * 0.8, sk.c, sk.c, sk.r * 2.6);
|
|
1102
|
+
halo.addColorStop(0, hexAlpha(tone, 0.12 * life)); halo.addColorStop(1, hexAlpha(tone, 0));
|
|
1103
|
+
paint.fillStyle = halo;
|
|
1104
|
+
paint.beginPath(); paint.arc(sk.c, sk.c, sk.r * 2.6, 0, Math.PI * 2); paint.fill();
|
|
1105
|
+
}
|
|
1106
|
+
paint.globalCompositeOperation = 'source-over';
|
|
1107
|
+
if (fibres) {
|
|
1108
|
+
// Viscous, not wired: a soft edge, a body of colour you can half see through, a wet highlight
|
|
1109
|
+
// along the side the light comes from, and light carried inside it.
|
|
1110
|
+
tubePass(paint, sk, deep, 0.55, 1.15);
|
|
1111
|
+
tubePass(paint, sk, tone, 0.72, 0.82, -0.06);
|
|
1112
|
+
paint.globalCompositeOperation = 'lighter';
|
|
1113
|
+
tubePass(paint, sk, pale, 0.12 + 0.1 * life, 0.5, 0);
|
|
1114
|
+
paint.globalCompositeOperation = 'source-over';
|
|
1115
|
+
tubePass(paint, sk, pale, 0.45 + 0.25 * life, 0.26, 0.24);
|
|
1116
|
+
// The sheath's beads: a pale ring between each, the way the photographs show the axon in segments.
|
|
1117
|
+
paint.strokeStyle = hexAlpha(deep, 0.85);
|
|
1118
|
+
for (const seg of sk.segs) if (seg.sheath) {
|
|
1119
|
+
const dx = seg.x1 - seg.x0, dy = seg.y1 - seg.y0;
|
|
1120
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
1121
|
+
const w = seg.w0 * 1.25;
|
|
1122
|
+
paint.lineWidth = Math.max(0.4, w * 0.16);
|
|
1123
|
+
paint.beginPath(); paint.moveTo(seg.x1 + (dy / d) * w * 0.55, seg.y1 - (dx / d) * w * 0.55); paint.lineTo(seg.x1 - (dy / d) * w * 0.55, seg.y1 + (dx / d) * w * 0.55); paint.stroke();
|
|
1124
|
+
}
|
|
1125
|
+
// Spines along the thin dendrites: short stalks with a head, where the synapses land.
|
|
1126
|
+
for (const seg of sk.segs) {
|
|
1127
|
+
if (seg.sheath || seg.w0 > sk.r * 0.24 || cellGrain(seg.x0, seg.y0, 1) > 0.42) continue;
|
|
1128
|
+
const dx = seg.x1 - seg.x0, dy = seg.y1 - seg.y0;
|
|
1129
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
1130
|
+
const side = cellGrain(seg.x0, seg.y0, 2) < 0.5 ? 1 : -1;
|
|
1131
|
+
const u = 0.3 + 0.4 * cellGrain(seg.x0, seg.y0, 3);
|
|
1132
|
+
const w = Math.max(0.35, (seg.w0 + seg.w1) / 2);
|
|
1133
|
+
const mx = seg.x0 + dx * u, my = seg.y0 + dy * u;
|
|
1134
|
+
const len = w * 1.4 + sk.r * 0.08;
|
|
1135
|
+
const ex = mx + (-dy / d) * side * len, ey = my + (dx / d) * side * len;
|
|
1136
|
+
paint.globalAlpha = (seg.z ?? 1) ** 1.5;
|
|
1137
|
+
paint.strokeStyle = hexAlpha(tone, 0.8);
|
|
1138
|
+
paint.lineWidth = Math.max(0.3, w * 0.4);
|
|
1139
|
+
paint.beginPath(); paint.moveTo(mx, my); paint.lineTo(ex, ey); paint.stroke();
|
|
1140
|
+
paint.fillStyle = hexAlpha(hexMix(tone, '#ffffff', 0.3), 0.85);
|
|
1141
|
+
paint.beginPath(); paint.arc(ex, ey, Math.max(0.35, w * 0.55), 0, Math.PI * 2); paint.fill();
|
|
1142
|
+
}
|
|
1143
|
+
paint.globalAlpha = 1;
|
|
1144
|
+
// Vesicles caught in the light, a few along each fibre.
|
|
1145
|
+
paint.globalCompositeOperation = 'lighter';
|
|
1146
|
+
for (const seg of sk.segs) {
|
|
1147
|
+
if (cellGrain(seg.x1, seg.y1, 4) > 0.3) continue;
|
|
1148
|
+
const u = cellGrain(seg.x1, seg.y1, 5);
|
|
1149
|
+
const w = (seg.w0 + seg.w1) / 2;
|
|
1150
|
+
paint.fillStyle = hexAlpha(pale, (0.25 + 0.3 * life) * ((seg.z ?? 1) ** 1.5));
|
|
1151
|
+
paint.beginPath(); paint.arc(seg.x0 + (seg.x1 - seg.x0) * u, seg.y0 + (seg.y1 - seg.y0) * u, Math.max(0.3, w * 0.22), 0, Math.PI * 2); paint.fill();
|
|
1152
|
+
}
|
|
1153
|
+
paint.globalCompositeOperation = 'source-over';
|
|
1154
|
+
}
|
|
1155
|
+
const { c, r } = sk;
|
|
1156
|
+
const lx = c + NEURON_LIGHT.x * r * 0.42, ly = c + NEURON_LIGHT.y * r * 0.42;
|
|
1157
|
+
if (body) {
|
|
1158
|
+
// The body: light at its upper left, its colour, dark toward its far edge, and a rim the light
|
|
1159
|
+
// behind it catches; the nucleus shows through, and what fills it gives it grain.
|
|
1160
|
+
const fill = paint.createRadialGradient(lx, ly, 0, c, c, r * 1.55);
|
|
1161
|
+
fill.addColorStop(0, hexAlpha(hexMix(tone, '#ffffff', 0.7), 0.95));
|
|
1162
|
+
fill.addColorStop(0.3, hexAlpha(hexMix(tone, '#ffffff', 0.2), 0.88));
|
|
1163
|
+
fill.addColorStop(0.7, hexAlpha(tone, 0.8));
|
|
1164
|
+
fill.addColorStop(1, hexAlpha(deep, 0.85));
|
|
1165
|
+
paint.fillStyle = fill;
|
|
1166
|
+
somaPath(paint, sk); paint.fill();
|
|
1167
|
+
paint.save();
|
|
1168
|
+
somaPath(paint, sk); paint.clip();
|
|
1169
|
+
const nucleus = paint.createRadialGradient(c + r * 0.12, c + r * 0.1, 0, c + r * 0.12, c + r * 0.1, r * 0.46);
|
|
1170
|
+
nucleus.addColorStop(0, hexAlpha(deep, 0.42)); nucleus.addColorStop(0.75, hexAlpha(deep, 0.22)); nucleus.addColorStop(1, hexAlpha(deep, 0));
|
|
1171
|
+
paint.fillStyle = nucleus;
|
|
1172
|
+
paint.beginPath(); paint.arc(c + r * 0.12, c + r * 0.1, r * 0.46, 0, Math.PI * 2); paint.fill();
|
|
1173
|
+
paint.fillStyle = hexAlpha(pale, 0.5 * life);
|
|
1174
|
+
paint.beginPath(); paint.arc(c + r * 0.2, c + r * 0.16, r * 0.1, 0, Math.PI * 2); paint.fill();
|
|
1175
|
+
// Its grain: dark granules and pale ones, scattered through it.
|
|
1176
|
+
for (let i = 0; i < 64; i += 1) {
|
|
1177
|
+
const a = cellGrain(i, c, 6) * Math.PI * 2, k = Math.sqrt(cellGrain(i, r, 7)) * r * 1.15;
|
|
1178
|
+
const dark = cellGrain(i, c, 8) < 0.55;
|
|
1179
|
+
paint.fillStyle = dark ? hexAlpha(deep, 0.2) : hexAlpha(pale, 0.22 * (0.5 + life));
|
|
1180
|
+
paint.beginPath(); paint.arc(c + Math.cos(a) * k, c + Math.sin(a) * k, r * (dark ? 0.05 + 0.05 * cellGrain(i, 1, 9) : 0.03 + 0.03 * cellGrain(i, 2, 9)), 0, Math.PI * 2); paint.fill();
|
|
1181
|
+
}
|
|
1182
|
+
paint.globalCompositeOperation = 'lighter';
|
|
1183
|
+
const rim = paint.createRadialGradient(c - NEURON_LIGHT.x * r * 0.5, c - NEURON_LIGHT.y * r * 0.5, r * 0.55, c, c, r * 1.5);
|
|
1184
|
+
rim.addColorStop(0, hexAlpha(tone, 0)); rim.addColorStop(0.75, hexAlpha(tone, 0)); rim.addColorStop(1, hexAlpha(pale, 0.25 * life + 0.06));
|
|
1185
|
+
paint.fillStyle = rim;
|
|
1186
|
+
paint.fillRect(c - r * 2, c - r * 2, r * 4, r * 4);
|
|
1187
|
+
paint.restore();
|
|
1188
|
+
// The shine.
|
|
1189
|
+
paint.globalCompositeOperation = 'lighter';
|
|
1190
|
+
const shine = paint.createRadialGradient(lx, ly, 0, lx, ly, r * 0.32);
|
|
1191
|
+
shine.addColorStop(0, `rgba(255, 255, 255, ${0.25 + 0.35 * life})`); shine.addColorStop(1, 'rgba(255, 255, 255, 0)');
|
|
1192
|
+
paint.fillStyle = shine;
|
|
1193
|
+
paint.beginPath(); paint.arc(lx, ly, r * 0.32, 0, Math.PI * 2); paint.fill();
|
|
1194
|
+
}
|
|
1195
|
+
// And the sparks at its tips.
|
|
1196
|
+
paint.globalCompositeOperation = 'lighter';
|
|
1197
|
+
if (fibres && life > 0.2) for (const tip of sk.tips) if (tip.spark) {
|
|
1198
|
+
const s = sk.r * 0.2 * tip.z;
|
|
1199
|
+
const spark = paint.createRadialGradient(tip.x, tip.y, 0, tip.x, tip.y, s);
|
|
1200
|
+
spark.addColorStop(0, hexAlpha('#fff3dc', 0.75 * life)); spark.addColorStop(0.35, hexAlpha(NEURON_SPARK, 0.45 * life)); spark.addColorStop(1, hexAlpha(NEURON_SPARK, 0));
|
|
1201
|
+
paint.fillStyle = spark;
|
|
1202
|
+
paint.beginPath(); paint.arc(tip.x, tip.y, s, 0, Math.PI * 2); paint.fill();
|
|
1203
|
+
}
|
|
1204
|
+
paint.globalCompositeOperation = 'source-over';
|
|
1205
|
+
}
|
|
1206
|
+
// A dead neuron, for a claim the room found false: no body left, only its shape in loose points
|
|
1207
|
+
// tied by a fine net, gaps where it has come apart, as in the third photograph.
|
|
1208
|
+
export function drawDeadNeuron(paint, sk, hex, rnd, { step = 3.2, dot = 1 } = {}) {
|
|
1209
|
+
const points = [];
|
|
1210
|
+
const net = hexMix(hex, '#3d5bff', 0.55);
|
|
1211
|
+
for (const seg of sk.segs) {
|
|
1212
|
+
const d = Math.hypot(seg.x1 - seg.x0, seg.y1 - seg.y0);
|
|
1213
|
+
const n = Math.max(1, Math.round(d / step));
|
|
1214
|
+
for (let i = 0; i < n; i += 1) {
|
|
1215
|
+
if (rnd() < 0.18) continue;
|
|
1216
|
+
const u = (i + rnd()) / n;
|
|
1217
|
+
const w = (seg.w0 + (seg.w1 - seg.w0) * u) * 0.7;
|
|
1218
|
+
points.push({ x: seg.x0 + (seg.x1 - seg.x0) * u + (rnd() - 0.5) * w * 2, y: seg.y0 + (seg.y1 - seg.y0) * u + (rnd() - 0.5) * w * 2, s: (0.45 + rnd() * (seg.w0 > sk.r * 0.3 ? 1.3 : 0.7)) * dot });
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const body = Math.round(sk.r * sk.r * 0.5 / (step * 0.6));
|
|
1222
|
+
for (let i = 0; i < body; i += 1) {
|
|
1223
|
+
const a = i * 2.39996, k = Math.sqrt((i + 0.5) / body);
|
|
1224
|
+
points.push({ x: sk.c + Math.cos(a) * sk.r * 1.1 * k + (rnd() - 0.5) * 1.5, y: sk.c + Math.sin(a) * sk.r * 1.1 * k + (rnd() - 0.5) * 1.5, s: (0.6 + rnd() * 1.4) * dot });
|
|
1225
|
+
}
|
|
1226
|
+
paint.globalCompositeOperation = 'lighter';
|
|
1227
|
+
paint.lineWidth = 0.5 * dot;
|
|
1228
|
+
paint.strokeStyle = hexAlpha(net, 0.5);
|
|
1229
|
+
paint.beginPath();
|
|
1230
|
+
const reach = (step * 2.6) ** 2;
|
|
1231
|
+
for (let i = 0; i < points.length; i += 1) {
|
|
1232
|
+
let tied = 0;
|
|
1233
|
+
for (let j = i + 1; j < points.length && tied < 3; j += 1) {
|
|
1234
|
+
const dx = points[j].x - points[i].x, dy = points[j].y - points[i].y;
|
|
1235
|
+
if (dx * dx + dy * dy < reach) { paint.moveTo(points[i].x, points[i].y); paint.lineTo(points[j].x, points[j].y); tied += 1; }
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
paint.stroke();
|
|
1239
|
+
for (const point of points) {
|
|
1240
|
+
paint.fillStyle = hexAlpha(hexMix(hex, '#ffe6ff', rnd() * 0.6), 0.85);
|
|
1241
|
+
paint.beginPath(); paint.arc(point.x, point.y, point.s, 0, Math.PI * 2); paint.fill();
|
|
1242
|
+
}
|
|
1243
|
+
paint.globalCompositeOperation = 'source-over';
|
|
1244
|
+
}
|
|
1245
|
+
// The sprite of one neuron: its colour, its shape, whether it lives, is going out or is dead, and
|
|
1246
|
+
// how alive (`life`, one of NEURON_LIVES: its colour baked in, so a neuron is one stamp, not two).
|
|
1247
|
+
// Seen small, or with motion reduced, this whole still drawing is what the map stamps.
|
|
1248
|
+
const neuronShape = (variant) => { let seed = (variant + 1) * 9301 + 49297; return () => { seed = (seed * 9301 + 49297) % 233280; return seed / 233280; }; };
|
|
1249
|
+
const neuronSkeletonOf = (variant) => { const rnd = neuronShape(variant); return { rnd, sk: neuronSkeleton(rnd, NEURON_SPRITE / 2, NEURON_SPRITE / 12, NEURON_SPRITE * 0.47, { depth: 4, thin: 0.35 }) }; };
|
|
1250
|
+
export const NEURON_LIVES = [0.15, 0.55, 1];
|
|
1251
|
+
export const neuronLife = (life) => NEURON_LIVES[life < 0.35 ? 0 : life < 0.7 ? 1 : 2];
|
|
1252
|
+
export function neuronSprite(hex, variant = 0, state = 'alive', life = state === 'spent' ? 0 : 1) {
|
|
1253
|
+
const key = `${hex}:${variant}:${state}:${life}`;
|
|
1254
|
+
let canvas = NEURON_SPRITES.get(key);
|
|
1255
|
+
if (canvas) return canvas;
|
|
1256
|
+
canvas = document.createElement('canvas');
|
|
1257
|
+
canvas.width = NEURON_SPRITE;
|
|
1258
|
+
canvas.height = NEURON_SPRITE;
|
|
1259
|
+
const paint = canvas.getContext('2d');
|
|
1260
|
+
const { rnd, sk } = neuronSkeletonOf(variant);
|
|
1261
|
+
if (state === 'dead') drawDeadNeuron(paint, sk, hex, rnd);
|
|
1262
|
+
else drawLivingNeuron(paint, sk, hex, life);
|
|
1263
|
+
NEURON_SPRITES.set(key, canvas);
|
|
1264
|
+
return canvas;
|
|
1265
|
+
}
|
|
1266
|
+
// THE RIG (2026-10-28): the same neuron cut into pieces — each trunk, each branch that leaves a
|
|
1267
|
+
// trunk, the axon, the body — laid side by side on one sheet, each with the point it hangs from.
|
|
1268
|
+
// The map stamps the pieces turned a little on their roots, each to its own slow rhythm, so the
|
|
1269
|
+
// dendrites move as living tissue does; the body stays, drawn last, over where they leave it.
|
|
1270
|
+
const NEURON_RIGS = new Map();
|
|
1271
|
+
const RIG_SCALE = 0.75; // the sheet's pixels per unit of the sprite: a rig is seen near, not huge
|
|
1272
|
+
export function neuronRig(hex, variant = 0, life = 1) {
|
|
1273
|
+
const key = `${hex}:${variant}:${life}`;
|
|
1274
|
+
let rig = NEURON_RIGS.get(key);
|
|
1275
|
+
if (rig) return rig;
|
|
1276
|
+
const { sk } = neuronSkeletonOf(variant);
|
|
1277
|
+
const pad = sk.r * 0.3 + 3;
|
|
1278
|
+
const reachOf = (w) => w * 1.6 + 1.5;
|
|
1279
|
+
const pieces = sk.parts.map((part, index) => ({ index, part, x0: Infinity, y0: Infinity, x1: -Infinity, y1: -Infinity }));
|
|
1280
|
+
const grow = (piece, x, y, w) => { piece.x0 = Math.min(piece.x0, x - w); piece.y0 = Math.min(piece.y0, y - w); piece.x1 = Math.max(piece.x1, x + w); piece.y1 = Math.max(piece.y1, y + w); };
|
|
1281
|
+
for (const seg of sk.segs) { const piece = pieces[seg.part]; if (!piece) continue; const w = reachOf(Math.max(seg.w0, seg.w1) * 1.7); grow(piece, seg.x0, seg.y0, w); grow(piece, seg.x1, seg.y1, w); }
|
|
1282
|
+
for (const knot of sk.knots) { const piece = pieces[knot.part]; if (piece) grow(piece, knot.x, knot.y, reachOf(knot.w)); }
|
|
1283
|
+
for (const tip of sk.tips) { const piece = pieces[tip.part]; if (piece) grow(piece, tip.x, tip.y, sk.r * 0.22 + 1); }
|
|
1284
|
+
const body = { index: -1, part: null, x0: sk.c - sk.r * 2.7, y0: sk.c - sk.r * 2.7, x1: sk.c + sk.r * 2.7, y1: sk.c + sk.r * 2.7 };
|
|
1285
|
+
const all = [...pieces.filter((piece) => Number.isFinite(piece.x0)), body];
|
|
1286
|
+
// On the sheet, shelf by shelf.
|
|
1287
|
+
const width = Math.ceil(NEURON_SPRITE * 2.2 * RIG_SCALE);
|
|
1288
|
+
let x = 0, y = 0, row = 0;
|
|
1289
|
+
for (const piece of all) {
|
|
1290
|
+
piece.x0 -= pad; piece.y0 -= pad; piece.x1 += pad; piece.y1 += pad;
|
|
1291
|
+
piece.w = Math.ceil((piece.x1 - piece.x0) * RIG_SCALE);
|
|
1292
|
+
piece.h = Math.ceil((piece.y1 - piece.y0) * RIG_SCALE);
|
|
1293
|
+
if (x + piece.w > width) { x = 0; y += row; row = 0; }
|
|
1294
|
+
piece.sx = x; piece.sy = y;
|
|
1295
|
+
x += piece.w;
|
|
1296
|
+
row = Math.max(row, piece.h);
|
|
1297
|
+
}
|
|
1298
|
+
const sheet = document.createElement('canvas');
|
|
1299
|
+
sheet.width = width;
|
|
1300
|
+
sheet.height = Math.max(1, y + row);
|
|
1301
|
+
const paint = sheet.getContext('2d');
|
|
1302
|
+
for (const piece of all) {
|
|
1303
|
+
paint.setTransform(RIG_SCALE, 0, 0, RIG_SCALE, piece.sx - piece.x0 * RIG_SCALE, piece.sy - piece.y0 * RIG_SCALE);
|
|
1304
|
+
paint.save();
|
|
1305
|
+
paint.beginPath(); paint.rect(piece.x0, piece.y0, piece.x1 - piece.x0, piece.y1 - piece.y0); paint.clip();
|
|
1306
|
+
if (piece.part) {
|
|
1307
|
+
const own = (one) => one.part === piece.index;
|
|
1308
|
+
drawLivingNeuron(paint, { ...sk, segs: sk.segs.filter(own), knots: sk.knots.filter(own), tips: sk.tips.filter(own) }, hex, life, { body: false });
|
|
1309
|
+
} else drawLivingNeuron(paint, sk, hex, life, { fibres: false });
|
|
1310
|
+
paint.restore();
|
|
1311
|
+
}
|
|
1312
|
+
paint.setTransform(1, 0, 0, 1, 0, 0);
|
|
1313
|
+
const trunks = all.filter((piece) => piece.part && piece.part.parent < 0);
|
|
1314
|
+
for (const trunk of trunks) trunk.kids = all.filter((piece) => piece.part && piece.part.parent === trunk.index);
|
|
1315
|
+
rig = { sheet, trunks, body };
|
|
1316
|
+
NEURON_RIGS.set(key, rig);
|
|
1317
|
+
return rig;
|
|
1318
|
+
}
|
|
1319
|
+
// How far a piece is turned at `t`: a trunk a little, a branch more, the axon hardly; two slow waves
|
|
1320
|
+
// of its own each, so no two pieces and no two neurons move together.
|
|
1321
|
+
function rigSway(t, seed, index, kind) {
|
|
1322
|
+
const reach = kind === 'axon' ? 0.035 : kind === 'trunk' ? 0.1 : 0.22;
|
|
1323
|
+
const pace = 0.5 + (((seed * 7.13 + index * 0.37) % 1) + 1) % 1 * 0.4;
|
|
1324
|
+
return reach * (0.72 * Math.sin(pace * t + seed * 3 + index * 1.9) + 0.28 * Math.sin(pace * 0.53 * t + index * 2.7 + seed));
|
|
1325
|
+
}
|
|
1326
|
+
export function drawNeuronRig(ctx, rig, x, y, side, t, seed) {
|
|
1327
|
+
const k = side / NEURON_SPRITE;
|
|
1328
|
+
const stamp = (piece) => ctx.drawImage(rig.sheet, piece.sx, piece.sy, piece.w, piece.h, piece.x0, piece.y0, piece.w / RIG_SCALE, piece.h / RIG_SCALE);
|
|
1329
|
+
const hang = (piece, turn, inner) => {
|
|
1330
|
+
ctx.save();
|
|
1331
|
+
ctx.translate(piece.part.x, piece.part.y);
|
|
1332
|
+
ctx.rotate(turn);
|
|
1333
|
+
ctx.translate(-piece.part.x, -piece.part.y);
|
|
1334
|
+
stamp(piece);
|
|
1335
|
+
inner?.();
|
|
1336
|
+
ctx.restore();
|
|
1337
|
+
};
|
|
1338
|
+
ctx.save();
|
|
1339
|
+
ctx.translate(x, y);
|
|
1340
|
+
ctx.scale(k, k);
|
|
1341
|
+
ctx.translate(-NEURON_SPRITE / 2, -NEURON_SPRITE / 2);
|
|
1342
|
+
for (const trunk of rig.trunks) {
|
|
1343
|
+
hang(trunk, rigSway(t, seed, trunk.index, trunk.part.kind), () => {
|
|
1344
|
+
for (const kid of trunk.kids) hang(kid, rigSway(t, seed, kid.index, 'branch'));
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
stamp(rig.body);
|
|
1348
|
+
ctx.restore();
|
|
1349
|
+
}
|
|
1350
|
+
// The neural mode's palette (2026-10-28): the photographs' own — the pale, see-through blue of a
|
|
1351
|
+
// living cell, its warm amber where light catches it, a sea green, a lavender —, membranes rather
|
|
1352
|
+
// than paint, one per kind so the legend still tells them apart; the dead one keeps its violet.
|
|
1353
|
+
export const NEURAL_COLORS = { decision: '#f0b47c', fact: '#9fd2ea', preference: '#8fd8c0', question: '#b7a8f2', aberration: '#cf74f0' };
|
|
1354
|
+
// A memory's kind as a whole neuron for the legend, drawn for its size: fewer branches, thicker,
|
|
1355
|
+
// the same light. `state` is alive, spent (not used) or dead (doubtful).
|
|
1356
|
+
export function neuronChip(hex, size = 16, state = 'alive') {
|
|
1357
|
+
const canvas = document.createElement('canvas');
|
|
1358
|
+
const ratio = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1;
|
|
1359
|
+
canvas.width = Math.round(size * ratio);
|
|
1360
|
+
canvas.height = Math.round(size * ratio);
|
|
1361
|
+
canvas.style.width = `${size}px`;
|
|
1362
|
+
canvas.style.height = `${size}px`;
|
|
1363
|
+
const paint = canvas.getContext('2d');
|
|
1364
|
+
paint.scale(canvas.width / 64, canvas.height / 64);
|
|
1365
|
+
let seed = 4 * 9301 + 49297;
|
|
1366
|
+
const rnd = () => { seed = (seed * 9301 + 49297) % 233280; return seed / 233280; };
|
|
1367
|
+
const sk = neuronSkeleton(rnd, 32, 8, 31, { depth: 1, thin: 1.6, trunks: 4 });
|
|
1368
|
+
if (state === 'dead') drawDeadNeuron(paint, sk, hex, rnd, { step: 4.5, dot: 1.6 });
|
|
1369
|
+
else drawLivingNeuron(paint, sk, hex, state === 'spent' ? 0 : 1);
|
|
1370
|
+
return canvas;
|
|
1371
|
+
}
|
|
1372
|
+
// A bundle of fibres from (x0, y0) to (x1, y1) bent through (cx, cy): a few strands that leave
|
|
1373
|
+
// together, part a little in the middle and meet again, the way an axon tract runs. Stroked
|
|
1374
|
+
// into the current path; the caller strokes it.
|
|
1375
|
+
export function fibreBundle(ctx, x0, y0, cx, cy, x1, y1, { strands = 3, spread = 3, seed = 0 } = {}) {
|
|
1376
|
+
const dx = x1 - x0, dy = y1 - y0;
|
|
1377
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
1378
|
+
const nx = -dy / d, ny = dx / d;
|
|
1379
|
+
for (let i = 0; i < strands; i += 1) {
|
|
1380
|
+
const k = strands === 1 ? 0 : (i / (strands - 1)) * 2 - 1;
|
|
1381
|
+
const wobble = Math.sin(seed * 3.1 + i * 1.7) * spread * 0.6;
|
|
1382
|
+
const off = k * spread + wobble;
|
|
1383
|
+
ctx.moveTo(x0, y0);
|
|
1384
|
+
ctx.bezierCurveTo(x0 + (cx - x0) * 0.66 + nx * off, y0 + (cy - y0) * 0.66 + ny * off, x1 + (cx - x1) * 0.66 + nx * off * 0.8, y1 + (cy - y1) * 0.66 + ny * off * 0.8, x1, y1);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
// A synapse as living tissue (2026-10-27): one viscous tube from (x0, y0) to (x1, y1) bent through
|
|
1388
|
+
// (cx, cy), full where it leaves each cell and drawn thin in the middle, the way two dendrites
|
|
1389
|
+
// reach for each other, wavering a little, with the same edge, colour and wet highlight as the
|
|
1390
|
+
// cells' own fibres. Widths are in the context's units, so it thickens as you come closer.
|
|
1391
|
+
export function gooTube(ctx, x0, y0, cx, cy, x1, y1, { w = 2, mid = 0.35, colour = '#7cc4ff', alpha = 1, seed = 0, min = 0.4 } = {}) {
|
|
1392
|
+
const dx = x1 - x0, dy = y1 - y0;
|
|
1393
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
1394
|
+
const nx = -dy / d, ny = dx / d;
|
|
1395
|
+
const points = [];
|
|
1396
|
+
const N = 18;
|
|
1397
|
+
for (let i = 0; i <= N; i += 1) {
|
|
1398
|
+
const u = i / N;
|
|
1399
|
+
const p = alongCurve(x0, y0, cx, cy, x1, y1, u);
|
|
1400
|
+
const wob = Math.sin(u * Math.PI * 3 + seed) * Math.sin(u * Math.PI) * Math.min(14, d * 0.025);
|
|
1401
|
+
points.push({ x: p.x + nx * wob, y: p.y + ny * wob, w: w * (1 - (1 - mid) * Math.sin(u * Math.PI)) });
|
|
1402
|
+
}
|
|
1403
|
+
// Each pass is one filled outline — its two edges walked out along the normals, its ends inside
|
|
1404
|
+
// the cells — so the tube is a single piece with no seams.
|
|
1405
|
+
for (const [tint, a, k, toward] of [[hexMix(colour, '#050a14', 0.62), 0.5, 1.15, 0], [colour, 0.62, 0.8, -0.06], [hexMix(colour, '#ffffff', 0.55), 0.42, 0.26, 0.24]]) {
|
|
1406
|
+
const left = [], right = [];
|
|
1407
|
+
for (let i = 0; i <= N; i += 1) {
|
|
1408
|
+
const p = points[Math.max(0, i - 1)], q = points[Math.min(N, i + 1)];
|
|
1409
|
+
const sx = q.x - p.x, sy = q.y - p.y;
|
|
1410
|
+
const sd = Math.hypot(sx, sy) || 1;
|
|
1411
|
+
let ox = -sy / sd, oy = sx / sd;
|
|
1412
|
+
if (ox * NEURON_LIGHT.x + oy * NEURON_LIGHT.y < 0) { ox = -ox; oy = -oy; }
|
|
1413
|
+
const half = Math.max(min, points[i].w * k) / 2;
|
|
1414
|
+
const cx0 = points[i].x + ox * toward * half * 2, cy0 = points[i].y + oy * toward * half * 2;
|
|
1415
|
+
left.push([cx0 + ox * half, cy0 + oy * half]);
|
|
1416
|
+
right.push([cx0 - ox * half, cy0 - oy * half]);
|
|
1417
|
+
}
|
|
1418
|
+
ctx.fillStyle = hexAlpha(tint, a * alpha);
|
|
1419
|
+
ctx.beginPath();
|
|
1420
|
+
ctx.moveTo(left[0][0], left[0][1]);
|
|
1421
|
+
for (const [x, y] of left) ctx.lineTo(x, y);
|
|
1422
|
+
for (let i = N; i >= 0; i -= 1) ctx.lineTo(right[i][0], right[i][1]);
|
|
1423
|
+
ctx.closePath();
|
|
1424
|
+
ctx.fill();
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
933
1427
|
// The bulb's cells, laid out once: a golden-angle spiral through a body a little wider above,
|
|
934
1428
|
// most of them near its skin so its shape reads, a warm few deep inside, and a stem below.
|
|
935
1429
|
const BULB_TONES = {
|
|
@@ -962,15 +1456,44 @@ export const BULB = (() => {
|
|
|
962
1456
|
.filter((one) => one.j !== i).sort((a, b) => a.d - b.d).slice(0, 2);
|
|
963
1457
|
for (const { j } of near) { const key = i < j ? `${i}-${j}` : `${j}-${i}`; if (!seen.has(key)) { seen.add(key); links.push([i, j]); } }
|
|
964
1458
|
});
|
|
965
|
-
|
|
1459
|
+
// Who stands next to whom, for the sparks that run through it.
|
|
1460
|
+
const near = cells.map(() => []);
|
|
1461
|
+
for (const [i, j] of links) { near[i].push(j); near[j].push(i); }
|
|
1462
|
+
return { cells, links, near };
|
|
966
1463
|
})();
|
|
1464
|
+
// ITS ELECTRICAL ACTIVITY (2026-10-27): sparks run cell to cell inside the bulb all the time, the way
|
|
1465
|
+
// a brain is never quiet — a few at once, each a short path along its fibres that lights as it
|
|
1466
|
+
// goes and fades behind. Read from the time alone: no state, the same frame for the same instant.
|
|
1467
|
+
const SPARK_SLOTS = 7;
|
|
1468
|
+
const sparkNoise = (a, b) => (((Math.sin(a * 127.1 + b * 311.7) * 43758.5453) % 1) + 1) % 1;
|
|
1469
|
+
function bulbSparks(t, count = SPARK_SLOTS) {
|
|
1470
|
+
const out = [];
|
|
1471
|
+
for (let k = 0; k < count; k += 1) {
|
|
1472
|
+
const period = 0.85 + k * 0.17;
|
|
1473
|
+
const shifted = t + k * 0.41;
|
|
1474
|
+
const n = Math.floor(shifted / period);
|
|
1475
|
+
const phase = (shifted - n * period) / period;
|
|
1476
|
+
let cell = Math.floor(sparkNoise(k + 1, n) * BULB.cells.length);
|
|
1477
|
+
const path = [cell];
|
|
1478
|
+
const steps = 4 + Math.floor(sparkNoise(n, k + 7) * 5);
|
|
1479
|
+
for (let i = 0; i < steps; i += 1) {
|
|
1480
|
+
const options = BULB.near[cell].filter((one) => !path.includes(one));
|
|
1481
|
+
if (!options.length) break;
|
|
1482
|
+
cell = options[Math.floor(sparkNoise(n * 13 + i, k) * options.length)];
|
|
1483
|
+
path.push(cell);
|
|
1484
|
+
}
|
|
1485
|
+
out.push({ path, phase });
|
|
1486
|
+
}
|
|
1487
|
+
return out;
|
|
1488
|
+
}
|
|
967
1489
|
// The bulb, drawn at (x, y) with radius R in whatever space the context is in; `px` is one css
|
|
968
1490
|
// pixel in that space. It turns slowly on its own besides the scene's turn, beats with the heart,
|
|
969
1491
|
// answers when pulses come home (`lit`), flushes red in an alarm, and flashes as the mode comes on.
|
|
970
1492
|
export function drawNeuralBulb(ctx, x, y, R, t, { yaw = 0, pitch = 0, beat = 0, lit = 0, alarm = 0, px = 1, light = 1, ignite = 1, tone = 'mother', still = false } = {}) {
|
|
971
1493
|
const colours = BULB_TONES[tone] ?? BULB_TONES.mother;
|
|
972
1494
|
const turn = yaw + (still ? 0 : t * 0.07);
|
|
973
|
-
|
|
1495
|
+
// Turned exactly as the memories are (2026-10-27), so the body and what it holds are one thing in space.
|
|
1496
|
+
const cy = Math.cos(turn), sy = Math.sin(turn), cp = Math.cos(pitch), sp = Math.sin(pitch);
|
|
974
1497
|
const flash = ignite < 0.3 ? 1 - ignite / 0.3 : 0;
|
|
975
1498
|
const energy = Math.min(1.6, (0.62 + 0.38 * beat + 0.45 * Math.min(1, lit) + 1.2 * flash) * light);
|
|
976
1499
|
const reach = R * 1.12;
|
|
@@ -996,6 +1519,41 @@ export function drawNeuralBulb(ctx, x, y, R, t, { yaw = 0, pitch = 0, beat = 0,
|
|
|
996
1519
|
ctx.beginPath();
|
|
997
1520
|
for (const [i, j] of BULB.links) { ctx.moveTo(at[i].x, at[i].y); ctx.lineTo(at[j].x, at[j].y); }
|
|
998
1521
|
ctx.stroke();
|
|
1522
|
+
// Its electrical activity: each spark's head running along its path, the stretch behind it fading,
|
|
1523
|
+
// and the cell it reaches flaring.
|
|
1524
|
+
if (!still) {
|
|
1525
|
+
ctx.lineCap = 'round';
|
|
1526
|
+
for (const spark of bulbSparks(t)) {
|
|
1527
|
+
const reach = spark.phase * 1.35 * (spark.path.length - 1);
|
|
1528
|
+
for (let i = 0; i < spark.path.length - 1; i += 1) {
|
|
1529
|
+
const age = reach - i;
|
|
1530
|
+
if (age < 0 || age > 2.6) continue;
|
|
1531
|
+
const a = at[spark.path[i]], b = at[spark.path[i + 1]];
|
|
1532
|
+
const part = Math.min(1, age);
|
|
1533
|
+
const fade = Math.max(0, 1 - Math.max(0, age - 1) / 1.6);
|
|
1534
|
+
// Broken, as a discharge is: the segment bends at two points that shake each frame.
|
|
1535
|
+
const ex = a.x + (b.x - a.x) * part, ey = a.y + (b.y - a.y) * part;
|
|
1536
|
+
const nx = -(ey - a.y), ny = ex - a.x;
|
|
1537
|
+
const jag = (k) => (sparkNoise(t * 60 + i, k) - 0.5) * 0.35;
|
|
1538
|
+
const p1 = { x: a.x + (ex - a.x) * 0.33 + nx * jag(1), y: a.y + (ey - a.y) * 0.33 + ny * jag(1) };
|
|
1539
|
+
const p2 = { x: a.x + (ex - a.x) * 0.66 + nx * jag(2), y: a.y + (ey - a.y) * 0.66 + ny * jag(2) };
|
|
1540
|
+
const tone = alarm ? '255, 120, 100' : '170, 225, 255';
|
|
1541
|
+
ctx.strokeStyle = `rgba(${tone}, ${0.22 * fade * light})`;
|
|
1542
|
+
ctx.lineWidth = (4 * fade + 1) * px;
|
|
1543
|
+
ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(p1.x, p1.y); ctx.lineTo(p2.x, p2.y); ctx.lineTo(ex, ey); ctx.stroke();
|
|
1544
|
+
ctx.strokeStyle = alarm ? `rgba(255, 190, 180, ${0.85 * fade * light})` : `rgba(230, 246, 255, ${0.85 * fade * light})`;
|
|
1545
|
+
ctx.lineWidth = (1 * fade + 0.3) * px;
|
|
1546
|
+
ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(p1.x, p1.y); ctx.lineTo(p2.x, p2.y); ctx.lineTo(ex, ey); ctx.stroke();
|
|
1547
|
+
if (age >= 1 && age < 1.5) {
|
|
1548
|
+
const flare = (1.5 - age) * 2;
|
|
1549
|
+
const size = 7 * flare * px;
|
|
1550
|
+
ctx.globalAlpha = Math.min(1, 0.9 * flare * light);
|
|
1551
|
+
ctx.drawImage(neuronGlow(alarm ? colours.alarm : '#d8f1ff'), b.x - size, b.y - size, size * 2, size * 2);
|
|
1552
|
+
ctx.globalAlpha = 1;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
999
1557
|
// The cells, the near side brighter, the heart swelling on the beat.
|
|
1000
1558
|
for (const point of at) {
|
|
1001
1559
|
const inner = 1 - point.cell.out;
|
|
@@ -1005,7 +1563,7 @@ export function drawNeuralBulb(ctx, x, y, R, t, { yaw = 0, pitch = 0, beat = 0,
|
|
|
1005
1563
|
ctx.drawImage(neuronGlow(hex), point.x - size, point.y - size, size * 2, size * 2);
|
|
1006
1564
|
}
|
|
1007
1565
|
// The nucleus: one wide soft light at the centre.
|
|
1008
|
-
const heart = R * (0.
|
|
1566
|
+
const heart = R * (0.5 + 0.06 * beat + 0.4 * flash);
|
|
1009
1567
|
ctx.globalAlpha = Math.min(1, (0.55 + 0.35 * beat) * energy);
|
|
1010
1568
|
ctx.drawImage(neuronGlow(alarm ? colours.alarm : colours.heart), x - heart, y - heart, heart * 2, heart * 2);
|
|
1011
1569
|
ctx.globalAlpha = 1;
|
|
@@ -1217,9 +1775,11 @@ export function createNostromo(nostromo) {
|
|
|
1217
1775
|
const pitchTo = Math.max(-PITCH_LIMIT, Math.min(PITCH_LIMIT, Math.atan2(held.wy, across)));
|
|
1218
1776
|
const yaw = nostromo.yaw ?? 0;
|
|
1219
1777
|
const short = ((yawTo - yaw + Math.PI) % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2) - Math.PI;
|
|
1778
|
+
// The head turns freely now, so it may be upside down: the tip back is the short way round too.
|
|
1779
|
+
const tip = ((pitchTo - (nostromo.pitch ?? 0) + Math.PI) % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2) - Math.PI;
|
|
1220
1780
|
const step = Math.min(1, FOCUS_TURN * dt);
|
|
1221
1781
|
nostromo.yaw = yaw + short * step;
|
|
1222
|
-
nostromo.pitch = (nostromo.pitch ?? 0) +
|
|
1782
|
+
nostromo.pitch = (nostromo.pitch ?? 0) + tip * step;
|
|
1223
1783
|
}
|
|
1224
1784
|
|
|
1225
1785
|
function projectNostromo() {
|
|
@@ -1965,6 +2525,44 @@ export function createNostromo(nostromo) {
|
|
|
1965
2525
|
ctx.restore();
|
|
1966
2526
|
}
|
|
1967
2527
|
|
|
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();
|
|
2556
|
+
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();
|
|
2564
|
+
}
|
|
2565
|
+
|
|
1968
2566
|
// The glow: the light a star gives off, clinging to it in a tight bloom the width of a finger,
|
|
1969
2567
|
// the same all the way round because nothing else is lighting it. It carries past the body
|
|
1970
2568
|
// and stops there, so it belongs to the star rather than hanging off it.
|
|
@@ -2274,6 +2872,8 @@ export function createNostromo(nostromo) {
|
|
|
2274
2872
|
ctx.drawImage(from.canvas, 0, 0);
|
|
2275
2873
|
ctx.restore();
|
|
2276
2874
|
}
|
|
2875
|
+
// A memory's colour in this drawing: the photographs' palette, one hue per kind.
|
|
2876
|
+
const neuralTone = (node) => NEURAL_COLORS[node.memory?.kind] ?? node.color;
|
|
2277
2877
|
function drawNeural(t) {
|
|
2278
2878
|
const ctx = nostromo.canvas.getContext('2d');
|
|
2279
2879
|
const { w, h, dpr } = nostromo.size;
|
|
@@ -2282,7 +2882,35 @@ export function createNostromo(nostromo) {
|
|
|
2282
2882
|
const alarm = nostromo.alarm ? Math.max(0, 1 - (t - nostromo.alarm) / 3.6) : 0;
|
|
2283
2883
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
2284
2884
|
ctx.clearRect(0, 0, w, h);
|
|
2285
|
-
if (!nostromo.bare)
|
|
2885
|
+
if (!nostromo.bare) {
|
|
2886
|
+
neuralGround(ctx, w, h, beat);
|
|
2887
|
+
// Depth: cells far behind the scene, out of focus, drifting slowly the other way.
|
|
2888
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
2889
|
+
for (let i = 0; i < 18; i += 1) {
|
|
2890
|
+
const hue = i % 3 === 0 ? NEURAL_COLORS.decision : NEURAL_COLORS.fact;
|
|
2891
|
+
const bx = ((Math.sin(i * 12.9898) * 43758.5453) % 1 + 1) % 1;
|
|
2892
|
+
const by = ((Math.sin(i * 78.233) * 12345.6789) % 1 + 1) % 1;
|
|
2893
|
+
const drift = nostromo.reduced ? 0 : Math.sin(t * 0.05 + i) * 12;
|
|
2894
|
+
const size = 22 + (i % 5) * 14;
|
|
2895
|
+
ctx.globalAlpha = 0.035 + (i % 4) * 0.012;
|
|
2896
|
+
ctx.drawImage(neuronGlow(hue), bx * w + drift - (cam.x ?? 0) * 0.02 - size, by * h - drift * 0.6 - (cam.y ?? 0) * 0.02 - size, size * 2, size * 2);
|
|
2897
|
+
}
|
|
2898
|
+
// What floats between the cells, as in the photographs (2026-10-28): small warm motes and a few
|
|
2899
|
+
// cold ones, drifting slowly and breathing in and out of the light.
|
|
2900
|
+
for (let i = 0; i < 42; i += 1) {
|
|
2901
|
+
const mx = ((Math.sin(i * 91.7) * 23456.789) % 1 + 1) % 1;
|
|
2902
|
+
const my = ((Math.sin(i * 47.3) * 34567.891) % 1 + 1) % 1;
|
|
2903
|
+
const float = nostromo.reduced ? 0 : t * (4 + (i % 7));
|
|
2904
|
+
const px0 = ((mx * w + float * (i % 2 ? 1 : -0.6) - (cam.x ?? 0) * 0.05) % w + w) % w;
|
|
2905
|
+
const py0 = ((my * h - float * 0.5 - (cam.y ?? 0) * 0.05) % h + h) % h;
|
|
2906
|
+
const breath = nostromo.reduced ? 0.7 : 0.45 + 0.55 * Math.abs(Math.sin(t * 0.4 + i * 1.3));
|
|
2907
|
+
const size = 1.5 + (i % 4);
|
|
2908
|
+
ctx.globalAlpha = (i % 3 ? 0.32 : 0.22) * breath;
|
|
2909
|
+
ctx.drawImage(neuronGlow(i % 5 === 0 ? NEURAL_COLORS.fact : NEURON_SPARK), px0 - size, py0 - size, size * 2, size * 2);
|
|
2910
|
+
}
|
|
2911
|
+
ctx.globalAlpha = 1;
|
|
2912
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
2913
|
+
}
|
|
2286
2914
|
ctx.save();
|
|
2287
2915
|
ctx.translate(w / 2, h / 2);
|
|
2288
2916
|
ctx.scale(cam.scale, cam.scale);
|
|
@@ -2325,21 +2953,32 @@ export function createNostromo(nostromo) {
|
|
|
2325
2953
|
ctx.lineCap = 'round';
|
|
2326
2954
|
// The axons from the core, then the synapses between memories: each set in one stroke.
|
|
2327
2955
|
const reveal = front === Infinity ? 1 : ignite;
|
|
2328
|
-
|
|
2329
|
-
ctx.
|
|
2956
|
+
// Tracts, not lines (2026-10-27): each axon and each synapse a few strands that part and meet.
|
|
2957
|
+
ctx.strokeStyle = `rgba(${NEURAL_AXON}, ${0.16 * farLight * reveal})`;
|
|
2958
|
+
ctx.lineWidth = 0.7 * px;
|
|
2330
2959
|
ctx.beginPath();
|
|
2331
|
-
for (const node of nodes) if (!node.forgetting && shown(node) > 0)
|
|
2960
|
+
for (const node of nodes) if (!node.forgetting && shown(node) > 0) fibreBundle(ctx, node.rimX, node.rimY, node.cx, node.cy, node.x, node.y, { strands: 3, spread: 4 * px * farSize, seed: node.seed });
|
|
2332
2961
|
ctx.stroke();
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
ctx.
|
|
2962
|
+
// Between two memories, tissue in the colours of both (2026-10-27): one viscous tube that leaves
|
|
2963
|
+
// each cell full and thins between them, and two fine fibres peeling off it. Nearer is thicker.
|
|
2964
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
2336
2965
|
for (const link of nostromo.links) {
|
|
2337
2966
|
const a = byId.get(link.a);
|
|
2338
2967
|
const b = byId.get(link.b);
|
|
2339
2968
|
if (!a || !b || shown(a) <= 0 || shown(b) <= 0) continue;
|
|
2340
|
-
|
|
2969
|
+
const colour = hexMix(neuralTone(a), neuralTone(b), 0.5);
|
|
2970
|
+
const persp = ((a.r3 ? a.r / a.r3 : 1) + (b.r3 ? b.r / b.r3 : 1)) / 2;
|
|
2971
|
+
const depthLight = 0.55 + 0.45 * Math.min(1, Math.max(0, (((a.depth ?? 0) + (b.depth ?? 0)) / 2 + 700) / 1400));
|
|
2972
|
+
gooTube(ctx, a.x, a.y, link.cx, link.cy, b.x, b.y, { w: 2.6 * persp * farSize, mid: 0.3, colour, alpha: 0.75 * farLight * reveal * depthLight, seed: a.seed + b.seed, min: 0.5 * px });
|
|
2973
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
2974
|
+
ctx.strokeStyle = hexAlpha(colour, 0.16 * farLight * reveal * depthLight);
|
|
2975
|
+
ctx.lineWidth = 0.5 * px;
|
|
2976
|
+
ctx.beginPath();
|
|
2977
|
+
fibreBundle(ctx, a.x, a.y, link.cx, link.cy, b.x, b.y, { strands: 2, spread: 9 * px * farSize, seed: a.seed + b.seed });
|
|
2978
|
+
ctx.stroke();
|
|
2979
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
2341
2980
|
}
|
|
2342
|
-
ctx.
|
|
2981
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
2343
2982
|
// A synapse whose neurons are lit answers in their colours.
|
|
2344
2983
|
for (const link of nostromo.links) {
|
|
2345
2984
|
const a = byId.get(link.a);
|
|
@@ -2347,8 +2986,8 @@ export function createNostromo(nostromo) {
|
|
|
2347
2986
|
if (!a || !b) continue;
|
|
2348
2987
|
const glow = Math.max(lightOf(a), lightOf(b)) * Math.min(shown(a), shown(b));
|
|
2349
2988
|
if (glow < 0.12) continue;
|
|
2350
|
-
ctx.strokeStyle = hexAlpha(hexMix(a
|
|
2351
|
-
ctx.lineWidth = (0.
|
|
2989
|
+
ctx.strokeStyle = hexAlpha(hexMix(neuralTone(a), neuralTone(b), 0.5), Math.min(0.4, 0.2 * glow) * farLight);
|
|
2990
|
+
ctx.lineWidth = (0.7 + 0.4 * Math.min(1, glow)) * px;
|
|
2352
2991
|
ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.quadraticCurveTo(link.cx, link.cy, b.x, b.y); ctx.stroke();
|
|
2353
2992
|
}
|
|
2354
2993
|
// The pulses: a head of light and the stretch of path it has just lit, fading behind it.
|
|
@@ -2398,31 +3037,61 @@ export function createNostromo(nostromo) {
|
|
|
2398
3037
|
ctx.beginPath(); ctx.arc(0, 0, front, 0, Math.PI * 2); ctx.stroke();
|
|
2399
3038
|
}
|
|
2400
3039
|
ctx.globalCompositeOperation = 'source-over';
|
|
2401
|
-
// The
|
|
2402
|
-
|
|
2403
|
-
//
|
|
2404
|
-
//
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
if (node.forgetting || node.scale <= 0.01) continue;
|
|
3040
|
+
// The neurons, each a cell of its kind (2026-10-27): the more the room leans on one, the more
|
|
3041
|
+
// alive it is — larger, its colour full, a breath of light round it; one the room no longer uses
|
|
3042
|
+
// goes out, grey and flickering lower the less it was used; a claim found false is a dead cell,
|
|
3043
|
+
// only its shape in points. What reaches a neuron now lights it from the heart.
|
|
3044
|
+
const drawNeuron = (node) => {
|
|
3045
|
+
if (node.forgetting || node.scale <= 0.01) return;
|
|
2408
3046
|
const seen = shown(node);
|
|
2409
|
-
if (seen <= 0)
|
|
3047
|
+
if (seen <= 0) return;
|
|
3048
|
+
// Truly in space (2026-10-27): a nearer cell is larger, a further one smaller and dimmer.
|
|
3049
|
+
const persp = node.r3 ? node.r / node.r3 : 1;
|
|
2410
3050
|
const near = 0.55 + 0.45 * Math.min(1, Math.max(0, ((node.depth ?? 0) + 700) / 1400));
|
|
3051
|
+
const activity = node.activity ?? 0;
|
|
3052
|
+
const shape = Math.floor((node.seed * 1000) % NEURON_SHAPES);
|
|
3053
|
+
const fade = seen * near * farLight;
|
|
2411
3054
|
if (node.memory.kind === COLLAPSED) {
|
|
3055
|
+
const side = 5 * persp * farSize * 12 * (0.6 + 0.4 * node.scale);
|
|
2412
3056
|
ctx.globalCompositeOperation = 'source-over';
|
|
2413
|
-
ctx.
|
|
2414
|
-
ctx.
|
|
2415
|
-
|
|
2416
|
-
ctx.globalCompositeOperation = 'lighter';
|
|
2417
|
-
continue;
|
|
3057
|
+
ctx.globalAlpha = 0.8 * fade;
|
|
3058
|
+
ctx.drawImage(neuronSprite(neuralTone(node), shape, 'dead'), node.x - side / 2, node.y - side / 2, side, side);
|
|
3059
|
+
return;
|
|
2418
3060
|
}
|
|
2419
3061
|
const light = lightOf(node);
|
|
2420
3062
|
const cold = !travels(node.memory);
|
|
2421
|
-
const
|
|
2422
|
-
const
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
3063
|
+
const life = cold ? 0.08 + 0.22 * activity : 0.3 + 0.7 * activity;
|
|
3064
|
+
const flicker = cold && !nostromo.reduced ? 0.78 + 0.22 * Math.sin(t * 1.3 + node.seed * 7) * Math.sin(t * 0.41 + node.seed) : 1;
|
|
3065
|
+
const breath = nostromo.reduced ? 1 : 0.85 + 0.15 * Math.sin(t * 1.4 + node.seed * 3);
|
|
3066
|
+
const soma = (4.5 + 3.5 * activity) * persp * farSize * (0.6 + 0.4 * node.scale);
|
|
3067
|
+
const side = soma * 12;
|
|
3068
|
+
const colour = neuralTone(node);
|
|
3069
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
3070
|
+
// How alive it is, baked into its colour (NEURON_LIVES), and how much light it has on top.
|
|
3071
|
+
const baked = neuronLife(life);
|
|
3072
|
+
ctx.globalAlpha = Math.min(1, 0.35 + 0.65 * life) * flicker * fade;
|
|
3073
|
+
// Alive and near enough to be seen moving, its dendrites sway (2026-10-28); small, or with motion
|
|
3074
|
+
// reduced, it is the still drawing.
|
|
3075
|
+
if (!nostromo.reduced && side * cam.scale > 44) drawNeuronRig(ctx, neuronRig(colour, shape, baked), node.x, node.y, side, t, node.seed);
|
|
3076
|
+
else ctx.drawImage(neuronSprite(colour, shape, 'alive', baked), node.x - side / 2, node.y - side / 2, side, side);
|
|
3077
|
+
ctx.globalCompositeOperation = 'lighter';
|
|
3078
|
+
// Its light: a breath round a cell in use, more while something reaches it — kept close to it.
|
|
3079
|
+
const glow = Math.max(light, cold ? 0 : 0.12 * life * breath);
|
|
3080
|
+
if (glow > 0.05) {
|
|
3081
|
+
const size = soma * (1.4 + 1.2 * Math.min(1, light));
|
|
3082
|
+
ctx.globalAlpha = Math.min(0.55, 0.45 * glow) * fade;
|
|
3083
|
+
ctx.drawImage(neuronGlow(colour), node.x - size, node.y - size, size * 2, size * 2);
|
|
3084
|
+
}
|
|
3085
|
+
};
|
|
3086
|
+
// Far to near: the cells behind the core first, then the core, then the ones before it, so
|
|
3087
|
+
// the body hides what is behind it from whichever side it is seen.
|
|
3088
|
+
const byDepth = nodes.slice().sort((p, q) => (p.depth ?? 0) - (q.depth ?? 0));
|
|
3089
|
+
for (const node of byDepth) if ((node.depth ?? 0) < 0) drawNeuron(node);
|
|
3090
|
+
ctx.globalAlpha = 1;
|
|
3091
|
+
ctx.globalCompositeOperation = 'source-over';
|
|
3092
|
+
// The central bulb.
|
|
3093
|
+
drawNeuralBulb(ctx, 0, 0, R, t, { yaw: (nostromo.spin ?? 0) * 0.2 + (nostromo.yaw ?? 0), pitch: nostromo.pitch ?? 0, beat, lit: nostromo.coreLit ?? 0, alarm, px, light: farLight, ignite, still: nostromo.reduced });
|
|
3094
|
+
for (const node of byDepth) if ((node.depth ?? 0) >= 0) drawNeuron(node);
|
|
2426
3095
|
ctx.globalAlpha = 1;
|
|
2427
3096
|
ctx.globalCompositeOperation = 'source-over';
|
|
2428
3097
|
for (const node of nodes) if (node === nostromo.hover && !nostromo.selected) drawSight(ctx, node.x, node.y, 9 * px, t, cam.scale);
|
|
@@ -2570,14 +3239,14 @@ export function createNostromo(nostromo) {
|
|
|
2570
3239
|
const raw = memories.map((memory) => rawActivity(memory, degree.get(memory.id) ?? 0));
|
|
2571
3240
|
const top = raw.reduce((best, value) => (value > best ? value : best), 0);
|
|
2572
3241
|
nostromo.rawTop = top;
|
|
3242
|
+
// How much each one knows, read against the richest of this archive (2026-10-28).
|
|
3243
|
+
const known = memories.map(knowledgeOf);
|
|
3244
|
+
const richest = known.reduce((best, value) => (value > best ? value : best), 0);
|
|
2573
3245
|
nostromo.nodes = memories.map((memory, index) => {
|
|
2574
3246
|
const sector = kinds.indexOf(memory.kind) < 0 ? 1 : kinds.indexOf(memory.kind);
|
|
2575
3247
|
const angle = (sector / kinds.length) * Math.PI * 2 + ((index % 7) / 7 - 0.5) * (Math.PI / 2.4) + Math.random() * 0.2;
|
|
2576
3248
|
const distance = 0.42 + Math.random() * 0.5;
|
|
2577
|
-
|
|
2578
|
-
// A far room sends how many sources a memory cites, not the list of them.
|
|
2579
|
-
const cited = memory.sources?.length ?? memory.sourcesCount ?? 0;
|
|
2580
|
-
return { memory, cold: memory.cold ?? null, angle, distance, activity: activityOf(raw[index], top), lit: 0, charge: 0, x: 0, y: 0, vx: 0, vy: 0, r: MEMORY_SCALE * (7 + Math.min(11, Math.log2(span + 1) * 2.2 + cited * 0.6)), scale: 1, seed: Math.random() * Math.PI * 2, rate: 0.5 + Math.random() * 0.9, color: travels(memory) ? (MEMORY_COLORS[memory.kind] ?? MEMORY_COLORS.fact) : hexMix(MEMORY_COLORS[memory.kind] ?? MEMORY_COLORS.fact, '#0b0f16', 0.52), placed: false };
|
|
3249
|
+
return { memory, cold: memory.cold ?? null, angle, distance, activity: activityOf(raw[index], top), lit: 0, charge: 0, x: 0, y: 0, vx: 0, vy: 0, r: MEMORY_SCALE * bodyOf(known[index], richest), scale: 1, seed: Math.random() * Math.PI * 2, rate: 0.5 + Math.random() * 0.9, color: travels(memory) ? (MEMORY_COLORS[memory.kind] ?? MEMORY_COLORS.fact) : hexMix(MEMORY_COLORS[memory.kind] ?? MEMORY_COLORS.fact, '#0b0f16', 0.52), placed: false };
|
|
2581
3250
|
});
|
|
2582
3251
|
return nostromo.nodes;
|
|
2583
3252
|
}
|