// Beyond the globe: the solar system and the stellar neighbourhood as node-and-lane boards (Master of Orion's structure).
// Data: the HYG star catalogue v4.1 (astronexus/HYG-Database, CC BY-SA 4.0) as hyg.csv, in the macro-view data dir.
// Usage (there): OUT=
bun gen-stars.ts
const outD = process.env.OUT ?? ".";
const r1 = (n: number) => Math.round(n * 10) / 10;
const LY = 3.26156;
const t = await Bun.file("hyg.csv").text();
const L = t.split("\n"); const h = L[0].split(",").map((s) => s.replace(/"/g, "")); const ix = (n: string) => h.indexOf(n);
type Star = { name: string; d: number; x: number; y: number; z: number; spect: string; mag: number };
const stars: Star[] = [{ name: "Sol", d: 0, x: 0, y: 0, z: 0, spect: "G2V", mag: 4.83 }];
for (const l of L.slice(1)) {
if (!l) continue; const c = l.split(",").map((s) => s.replace(/"/g, ""));
const d = +c[ix("dist")]; if (!(d > 0 && d <= 4.9)) continue;
stars.push({ name: c[ix("proper")] || c[ix("gl")] || "HYG " + c[ix("id")], d, x: +c[ix("x")], y: +c[ix("y")], z: +c[ix("z")], spect: c[ix("spect")], mag: +c[ix("absmag")] });
}
// one node per system: stars within 0.15 pc of a brighter one join it
type Sys = { name: string; members: Star[]; x: number; y: number; z: number; d: number; lead: Star };
const systems: Sys[] = [];
for (const s of [...stars].sort((a, b) => a.mag - b.mag)) {
const host = systems.find((q) => Math.hypot(q.x - s.x, q.y - s.y, q.z - s.z) < 0.15);
if (host) host.members.push(s); else systems.push({ name: s.name, members: [s], x: s.x, y: s.y, z: s.z, d: s.d, lead: s });
}
const rename: Record = { "Rigil Kentaurus": "Alpha Centauri", "Gl 71": "Tau Ceti", "Ran": "Epsilon Eridani", "Gl 845": "Epsilon Indi", "Gl 820A": "61 Cygni", "Gl 65A": "Luyten 726-8", "Gl 380": "Groombridge 1618", "Gl 674": "Gliese 674", "Gl 876": "Gliese 876", "GJ 1061": "GJ 1061", "Gl 725A": "Struve 2398", "Struve 2398 A": "Struve 2398" };
for (const s of systems) s.name = rename[s.name] ?? s.name;
// planets listed in the NASA Exoplanet Archive (a selection, by host)
const planets: Record = { "Alpha Centauri": 1, "Barnard's Star": 4, "Lalande 21185": 1, "Epsilon Eridani": 1, "Ross 128": 1, "Luyten's Star": 2, "Wolf 1061": 3, "Gliese 876": 4, "GJ 1061": 3, "Lacaille 9352": 2, "Groombridge 34": 1, "Tau Ceti": 4, "Gliese 674": 1, "Sol": 8 };
// lanes: each system to its nearest neighbours, up to 2.9 pc (9.5 ly), at least one each
const key = (a: number, b: number) => (a < b ? a + "-" + b : b + "-" + a);
const lanes = new Map();
systems.forEach((s, i) => {
const near = systems.map((q, j) => ({ j, d: Math.hypot(q.x - s.x, q.y - s.y, q.z - s.z) })).filter((o) => o.j !== i).sort((a, b) => a.d - b.d);
near.slice(0, 3).forEach((o, k) => { if (k === 0 || o.d < 2.9) lanes.set(key(i, o.j), [Math.min(i, o.j), Math.max(i, o.j), o.d]); });
});
const COL = (sp: string) => ({ O: "#9bb0ff", B: "#aabfff", A: "#e4ecff", F: "#fbf8ff", G: "#fff1b0", K: "#ffc27a", M: "#ff8a5c", D: "#dfe8ff" } as Record)[(sp.replace(/^(sd|d)/, "")[0] ?? "M").toUpperCase()] ?? "#ff8a5c";
const defs = ``;
const head = (W: number, H: number) => `");
console.log("systems", systems.length, "lanes", lanes.size, "with planets", systems.filter((q) => planets[q.name]).map((q) => q.name).join(", "));
const ac = systems.find((q) => q.name === "Alpha Centauri")!; const solL = [...lanes.values()].filter(([a, b]) => systems[a].name === "Sol" || systems[b].name === "Sol").map(([a, b, d]) => (systems[a].name === "Sol" ? systems[b] : systems[a]).name + " " + (d * LY).toFixed(1));
console.log("Sol lanes", solL.join(" | "), "AC members", ac.members.map((m) => m.name).join(","));
}
// ===== the solar system as a node board =====
{
const W = 960, H = 600, cx = 150, cy = 300;
const pl = [["Mercury", 0.39, "#b8a99a", 4], ["Venus", 0.72, "#e8cf9c", 6], ["Earth", 1, "#5c9bd6", 7], ["Mars", 1.52, "#d0714a", 5], ["Jupiter", 5.2, "#d9b38c", 13], ["Saturn", 9.54, "#e6d3a3", 11], ["Uranus", 19.2, "#9fd8e0", 9], ["Neptune", 30.1, "#5f84d9", 9]] as const;
const R = (au: number) => 70 + Math.log(1 + au * 2.2) * 150;
let s = head(W, H) + dust(W, H, 200);
s += ``;
pl.forEach(([n, au], i) => { const r = R(au); s += ``; });
const pos = pl.map(([n, au, c, sz], i) => { const a = -0.45 + (i % 3) * 0.42 + (i > 3 ? 0.1 : 0); const r = R(au); return { n, c, sz, x: cx + r * Math.cos(a), y: cy + r * Math.sin(a) }; });
// lanes: transfer routes between neighbours, plus the Moon off Earth
for (let i = 0; i < pos.length - 1; i++) s += ``;
const e = pos[2]; const moon = { x: e.x + 34, y: e.y - 30 };
s += `Moon`;
for (const p of pos) {
s += ``;
if (p.n === "Earth") s += ``;
s += `${p.n}`;
}
s += `Sun`;
await Bun.write(`${outD}/system.svg`, s + "");
}
console.log("done");