// Draws the macro-view mockup maps from real data into SVG. // Data (fetched once into this directory): // Natural Earth 10m/50m GeoJSON (land, countries, lakes, rivers, roads, railroads, provinces, places) // lc_z6.geojson: ESA WorldCover 2021 via tiles.cartopolis.org/tiles/landcover, z6 // cities.json: OSM place=city nodes from overpass.cartopolis.org // Usage: bun gen.ts const out = process.argv[2] ?? "."; const J = async (f: string) => Bun.file(f).json(); const [land, countries, lakes, rivers, roads, rails, provs, lc, cityJ, nePlaces] = await Promise.all([ J("ne_10m_land.geojson"), J("ne_50m_admin_0_countries.geojson"), J("ne_10m_lakes.geojson"), J("ne_10m_rivers_lake_centerlines.geojson"), J("ne_10m_roads.geojson"), J("ne_10m_railroads.geojson"), J("ne_10m_admin_1_states_provinces_lines.geojson"), J("lc_z6.geojson"), J("cities.json"), J("ne_10m_populated_places_simple.geojson"), ]); const countries10 = await J("ne_10m_admin_0_countries.geojson"); type BBox = [number, number, number, number]; // W S E N const merc = (lat: number) => Math.log(Math.tan(Math.PI / 4 + (lat * Math.PI) / 360)); function view(b: BBox, W: number, H: number) { const [w, s, e, n] = b; const sx = W / (e - w), y0 = merc(n), y1 = merc(s); const sy = H / (y0 - y1); const k = Math.min(sx, sy * (Math.PI / 180)); // keep conformal: px per degree lon const kx = k, ky = k * (180 / Math.PI); const cx = (w + e) / 2, cy = (y0 + y1) / 2; const P = (lon: number, lat: number): [number, number] => [W / 2 + (lon - cx) * kx, H / 2 - (merc(lat) - cy) * ky]; const inv = (x: number, y: number): [number, number] => { const lon = cx + (x - W / 2) / kx; const m = cy - (y - H / 2) / ky; return [lon, (Math.atan(Math.sinh(m)) * 180) / Math.PI]; }; // metres → px at a latitude const kmPx = (km: number, lat: number) => (km / (111.32 * Math.cos((lat * Math.PI) / 180))) * kx; return { W, H, b, P, inv, kmPx }; } type V = ReturnType; const r1 = (n: number) => Math.round(n * 10) / 10; function ringsOf(g: any): number[][][] { if (!g) return []; if (g.type === "Polygon") return g.coordinates; if (g.type === "MultiPolygon") return g.coordinates.flat(); if (g.type === "LineString") return [g.coordinates]; if (g.type === "MultiLineString") return g.coordinates; return []; } function bboxHit(ring: number[][], b: BBox, pad = 0.5) { let w = 1e9, s = 1e9, e = -1e9, n = -1e9; for (const [x, y] of ring) { if (x < w) w = x; if (x > e) e = x; if (y < s) s = y; if (y > n) n = y; } return !(e < b[0] - pad || w > b[2] + pad || n < b[1] - pad || s > b[3] + pad); } function path(v: V, g: any, closed: boolean, minPx = 0.6) { let d = ""; for (const ring of ringsOf(g)) { if (!bboxHit(ring, v.b)) continue; let last: [number, number] | null = null, seg = "", n = 0; for (const [lon, lat] of ring) { const p = v.P(lon, lat); if (last && Math.abs(p[0] - last[0]) < minPx && Math.abs(p[1] - last[1]) < minPx) continue; seg += (n ? "L" : "M") + r1(p[0]) + " " + r1(p[1]); last = p; n++; } if (n > 1) d += seg + (closed ? "Z" : ""); } return d; } const feats = (fc: any, f?: (p: any) => boolean) => fc.features.filter((x: any) => !f || f(x.properties)); // --- point in polygon over landcover, for hex classification ------------- type Poly = { kind: string; rings: number[][][]; bb: BBox }; const lcPolys: Poly[] = lc.features.filter((f: any) => f.properties.layer === "land").flatMap((f: any) => { const g = f.geometry; const polys = g.type === "Polygon" ? [g.coordinates] : g.type === "MultiPolygon" ? g.coordinates : []; return polys.map((rings: number[][][]) => { let w = 1e9, s = 1e9, e = -1e9, n = -1e9; for (const [x, y] of rings[0]) { w = Math.min(w, x); e = Math.max(e, x); s = Math.min(s, y); n = Math.max(n, y); } return { kind: f.properties.kind, rings, bb: [w, s, e, n] as BBox }; }); }); function inRing(r: number[][], x: number, y: number) { let c = false; for (let i = 0, j = r.length - 1; i < r.length; j = i++) { const [xi, yi] = r[i], [xj, yj] = r[j]; if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) c = !c; } return c; } function inRings(rings: number[][][], x: number, y: number) { if (!inRing(rings[0], x, y)) return false; for (let i = 1; i < rings.length; i++) if (inRing(rings[i], x, y)) return false; return true; } function kindAt(lon: number, lat: number): string | null { // later features draw on top; take the last hit (smallest usually) let k: string | null = null; for (const p of lcPolys) { const b = p.bb; if (lon < b[0] || lon > b[2] || lat < b[1] || lat > b[3]) continue; if (inRings(p.rings, lon, lat)) k = p.kind; } return k; } const landPolys = land.features.flatMap((f: any) => (f.geometry.type === "Polygon" ? [f.geometry.coordinates] : f.geometry.coordinates)); const isLand = (lon: number, lat: number) => landPolys.some((r: number[][][]) => inRings(r, lon, lat)) && !lakes.features.some((f: any) => (f.geometry.type === "Polygon" ? [f.geometry.coordinates] : f.geometry.coordinates).some((r: number[][][]) => inRings(r, lon, lat))); // --- palette --------------------------------------------------------------- const LC: Record = { farmland: "#979262", grassland: "#6f8a55", forest: "#3e5a3c", residential: "#8a817a", marsh: "#5f7c6e", heath: "#86727f", scrub: "#7b8559", bare_rock: "#cdc29c", }; const defs = ` `; function hexPath(cx: number, cy: number, r: number) { let d = ""; for (let i = 0; i < 6; i++) { const a = (Math.PI / 180) * (60 * i - 30); d += (i ? "L" : "M") + r1(cx + r * Math.cos(a)) + " " + r1(cy + r * Math.sin(a)); } return d + "Z"; } function hexCentres(W: number, H: number, r: number) { const out: [number, number][] = [], w = Math.sqrt(3) * r, h = 1.5 * r; for (let row = 0, y = 0; y < H + r; row++, y += h) for (let x = row % 2 ? w / 2 : 0; x < W + w; x += w) out.push([x, y]); return out; } // --- base map: sea, coast shallows, land cover, water, lines --------------- function baseMap(v: V, opt: { lc?: boolean; mute?: number; roads?: boolean; rails?: boolean; provinces?: boolean; lcData?: any; hexR?: number } = {}) { const landD = path(v, { type: "MultiPolygon", coordinates: landPolys }, true); const lakeD = lakes.features.map((f: any) => path(v, f.geometry, true)).join(""); let s = ``; s += ``; s += ``; s += ``; s += ``; if (opt.lc !== false) { const by: Record = {}; for (const f of (opt.lcData ?? lc).features) if (f.properties.layer === "land") by[f.properties.kind] = (by[f.properties.kind] ?? "") + path(v, f.geometry, true, 0.8); for (const k of ["farmland", "grassland", "scrub", "heath", "marsh", "bare_rock", "forest", "residential"]) { if (!by[k]) continue; s += ``; if (k === "forest") s += ``; if (k === "marsh") s += ``; } } if (opt.mute) s += ``; s += ``; s += ``; const riv = feats(rivers, (p) => p.featurecla !== "Lake Centerline").map((f: any) => path(v, f.geometry, false)).join(""); s += ``; if (opt.provinces) { const pv = feats(provs, (p) => ["NLD", "BEL", "DEU"].includes(p.adm0_a3)).map((f: any) => path(v, f.geometry, false)).join(""); s += ``; } if (opt.rails) { const rl = feats(rails, (p) => !p.disp_scale || true).map((f: any) => path(v, f.geometry, false)).join(""); s += ``; } if (opt.roads !== false) { const sec = feats(roads, (p) => p.continent === "Europe" && p.type === "Secondary Highway").map((f: any) => path(v, f.geometry, false)).join(""); const maj = feats(roads, (p) => p.continent === "Europe" && p.type === "Major Highway").map((f: any) => path(v, f.geometry, false)).join(""); s += ``; s += ``; } return s; } function countryLines(v: V, codes: string[], color: string, width = 3) { const fc = countries10; let s = ""; for (const f of fc.features) { if (!codes.includes(f.properties.ADM0_A3)) continue; const d = path(v, f.geometry, true); const id = "cc" + f.properties.ADM0_A3 + Math.round(Math.random() * 1e6); s += ``; s += ``; } return s; } // --- cities --------------------------------------------------------------- type City = { name: string; pop: number; lon: number; lat: number }; const cities: City[] = cityJ.elements.map((e: any) => ({ name: e.tags["name:en"] && e.tags.name === "Den Haag" ? "Den Haag" : e.tags.name, pop: +(e.tags.population || 0), lon: e.lon, lat: e.lat })); const foreign = ["Antwerpen", "Gent", "Brussels", "Liège", "Essen", "Duisburg", "Düsseldorf", "Cologne", "Dortmund", "Bonn", "Lille", "Brugge", "Wuppertal", "Hasselt", "Emden"]; for (const f of nePlaces.features) if (foreign.includes(f.properties.name)) cities.push({ name: f.properties.name === "Cologne" ? "Köln" : f.properties.name, pop: f.properties.pop_max, lon: f.geometry.coordinates[0], lat: f.geometry.coordinates[1] }); cities.sort((a, b) => b.pop - a.pop); const fmtPop = (n: number) => (n >= 1e6 ? (n / 1e6).toFixed(1) + "M" : Math.round(n / 1e3) + "k"); function banner(v: V, c: City, o: { color?: string; badge?: string; small?: boolean; dim?: boolean } = {}) { const [x, y] = v.P(c.lon, c.lat); if (x < -40 || y < -20 || x > v.W + 40 || y > v.H + 20) return ""; const big = c.pop >= 300000 && !o.small; const fs = big ? 15 : 12.5, h = big ? 26 : 21; const tw = c.name.length * fs * 0.6 + 8; const pw = fmtPop(c.pop).length * (fs - 2) * 0.62 + 12; const w = tw + pw + 10 + (o.badge ? 22 : 0); const col = o.color ?? "#13191b"; const op = o.dim ? 0.55 : 1; let s = ``; s += ``; s += ``; s += ``; s += ``; s += `${fmtPop(c.pop)}`; s += `${c.name}`; if (o.badge) s += `${o.badge}`; s += ``; return s; } function placeBanners(v: V, list: City[], max: number, f: (c: City, i: number) => string) { // greedy declutter in pixel space const taken: [number, number, number, number][] = []; let s = "", n = 0; for (const c of list) { if (n >= max) break; const [x, y] = v.P(c.lon, c.lat); if (x < 30 || x > v.W - 30 || y < 40 || y > v.H - 10) continue; const w = c.name.length * 9 + 60, box: [number, number, number, number] = [x - w / 2, y - 38, x + w / 2, y + 6]; if (taken.some((t) => !(box[2] < t[0] || box[0] > t[2] || box[3] < t[1] || box[1] > t[3]))) continue; taken.push(box); s += f(c, n); n++; } return s; } const svgWrap = (v: V, body: string) => ` ${defs}${body}`; // =========================================================================== // Scenario sheets (docs/mockups/scenarios). Everything above is the macro-view // generator's base map, copied so this folder stands on its own. // Extra data: ne_10m_admin_1_states_provinces.geojson (Natural Earth, polygons). // =========================================================================== const adm1 = await J("ne_10m_admin_1_states_provinces.geojson"); const polysOf = (g: any): number[][][][] => (g.type === "Polygon" ? [g.coordinates] : g.type === "MultiPolygon" ? g.coordinates : []); const bbOf = (pp: number[][][][]) => { let w = 1e9, s = 1e9, e = -1e9, n = -1e9; for (const p of pp) for (const [x, y] of p[0]) { if (x < w) w = x; if (x > e) e = x; if (y < s) s = y; if (y > n) n = y; } return [w, s, e, n]; }; type Region = { name: string; a3: string; pp: number[][][][]; bb: number[]; g: any }; const regionsOf = (a3s: string[]): Region[] => adm1.features.filter((f: any) => a3s.includes(f.properties.adm0_a3)).map((f: any) => { const pp = polysOf(f.geometry); return { name: f.properties.name, a3: f.properties.adm0_a3, pp, bb: bbOf(pp), g: f.geometry }; }); const inRegion = (r: Region, lon: number, lat: number) => lon >= r.bb[0] && lon <= r.bb[2] && lat >= r.bb[1] && lat <= r.bb[3] && r.pp.some((p) => inRings(p, lon, lat)); const kmBetween = (a: number[], b: number[]) => { const kx = 111.32 * Math.cos((((a[1] + b[1]) / 2) * Math.PI) / 180); return Math.hypot((b[0] - a[0]) * kx, (b[1] - a[1]) * 110.57); }; const EUR = ["POL","LTU","LVA","EST","DEU","CZE","SVK","NLD","BEL","DNK","AUT","HUN","SWE","FIN","FRA","LUX","CHE","ITA","SVN","HRV","ROU","NOR","GBR"]; const HOSTILE = ["RUS", "BLR"]; // the six NATO nuclear-sharing bases named in public reporting (as macro-view/gen.ts) const bases = [ { name: "Volkel", lon: 5.7086, lat: 51.6564 }, { name: "Kleine Brogel", lon: 5.47, lat: 51.1683 }, { name: "Büchel", lon: 7.0633, lat: 50.1736 }, { name: "Aviano", lon: 12.5961, lat: 46.0319 }, { name: "Ghedi", lon: 10.2678, lat: 45.4322 }, { name: "Incirlik", lon: 35.4259, lat: 37.0021 }, ]; // a dark political base for continent-scale scenario maps function politicalBase(v: V, o: { regionsOf?: string[] } = {}) { let s = ``; for (const f of countries10.features) { const a = f.properties.ADM0_A3; const d = path(v, f.geometry, true, 0.8); if (!d) continue; const fill = EUR.includes(a) ? "#22333b" : HOSTILE.includes(a) ? "#3a2526" : "#272b2c"; s += ``; } const lakeD = lakes.features.map((f: any) => path(v, f.geometry, true)).join(""); s += ``; const riv = feats(rivers, (p) => p.featurecla !== "Lake Centerline" && (p.scalerank ?? 9) <= 6).map((f: any) => path(v, f.geometry, false)).join(""); s += ``; if (o.regionsOf) { const rl = regionsOf(o.regionsOf).map((r) => path(v, r.g, true, 0.8)).join(""); s += ``; } for (const f of countries10.features) { const a = f.properties.ADM0_A3, d = path(v, f.geometry, true, 0.8); if (!d) continue; s += ``; } return s; } function capitals(v: V, minPop: number, dim = 1) { let s = ""; const seen = new Set(); for (const f of nePlaces.features) { const p = f.properties; if (p.pop_max < minPop || seen.has(p.name)) continue; if (!(p.adm0cap || p.pop_max > 2.5e6)) continue; const [x, y] = v.P(f.geometry.coordinates[0], f.geometry.coordinates[1]); if (x < 20 || y < 20 || x > v.W - 20 || y > v.H - 20) continue; seen.add(p.name); s += `${p.name}`; } return s; } const outD = process.env.OUT ?? "."; const which = (process.env.ONLY ?? "strat,nuke,drones,phone").split(","); // ===== A. the strategy map with community territories (Civ-style borders) ===== if (which.includes("strat")) { const v = view([2.6, 50.35, 9.4, 53.95], 1600, 1000); let s = `` + baseMap(v, { provinces: true, rails: true }) + ``; const R = 15, w = Math.sqrt(3) * R, h = 1.5 * R; const cell = (col: number, row: number): [number, number] => [col * w + (row % 2 ? w / 2 : 0), row * h]; const rows = Math.ceil(v.H / h) + 1, cols = Math.ceil(v.W / w) + 1; const hx = hexCentres(v.W, v.H, R).map(([x, y]) => hexPath(x, y, R)).join(""); s += ``; // invented communities' reach, as a set of hexes around a seat, Civ-style tinted territory with a glowing edge const comms = [ { name: "Groningen", lon: 6.567, lat: 53.219, km: 34, col: "#5cc6c0" }, { name: "Utrecht", lon: 5.12, lat: 52.09, km: 30, col: "#f2b84b" }, { name: "Eindhoven", lon: 5.478, lat: 51.441, km: 26, col: "#c58be0" }, { name: "Gent", lon: 3.72, lat: 51.054, km: 22, col: "#7fb1ff" }, ]; const owner: (number | -1)[][] = []; for (let r = 0; r < rows; r++) { owner[r] = []; for (let c = 0; c < cols; c++) { const [x, y] = cell(c, r); const [lon, lat] = v.inv(x, y); let o = -1, best = 1e9; comms.forEach((m, i) => { const d = kmBetween([lon, lat], [m.lon, m.lat]) / m.km; if (d < 1 && d < best) { best = d; o = i; } }); if (o >= 0 && !isLand(lon, lat)) o = -1; owner[r][c] = o; } } const nb = (c: number, r: number) => { const odd = r % 2; return [[c + 1, r], [c - 1, r], [c + (odd ? 1 : 0), r - 1], [c - (odd ? 0 : 1), r - 1], [c + (odd ? 1 : 0), r + 1], [c - (odd ? 0 : 1), r + 1]]; }; // hex corner i at angle 60i-30; edge between corners i and i+1 faces neighbour direction: const edgeDir = [[1, 0], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1]]; // placeholder, resolved below by geometry comms.forEach((m, i) => { let fill = "", edge = ""; for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) { if (owner[r][c] !== i) continue; const [x, y] = cell(c, r); fill += hexPath(x, y, R); const corners = [...Array(6)].map((_, k) => { const a = (Math.PI / 180) * (60 * k - 30); return [x + R * Math.cos(a), y + R * Math.sin(a)]; }); for (let k = 0; k < 6; k++) { const a = corners[k], b = corners[(k + 1) % 6]; const mx = (a[0] + b[0]) / 2, my = (a[1] + b[1]) / 2; // neighbour centre is mirror of own centre over this edge midpoint const nx = 2 * mx - x, ny = 2 * my - y; const nr = Math.round(ny / h), nc = Math.round((nx - (nr % 2 ? w / 2 : 0)) / w); const o = owner[nr]?.[nc] ?? -1; if (o !== i) edge += `M${r1(a[0])} ${r1(a[1])}L${r1(b[0])} ${r1(b[1])}`; } } void edgeDir; s += ``; s += ``; s += ``; }); // fog of data: east of the Ems the map has no fresh community data (invented) s += ` `; const [fx] = v.P(7.6, 52); s += ``; s += countryLines(v, ["NLD"], "#fd6012", 3); s += countryLines(v, ["BEL", "DEU"], "#d9cbb0", 1.5); s += placeBanners(v, cities, 24, (c) => banner(v, c, {})); // a stack of people, Civ-unit style counters (invented) for (const p of [{ lon: 5.0, lat: 52.37, n: 38 }, { lon: 4.48, lat: 51.92, n: 14 }, { lon: 6.57, lat: 53.22, n: 21 }, { lon: 5.48, lat: 51.44, n: 9 }]) { const [x, y] = v.P(p.lon, p.lat); s += `${p.n}`; } await Bun.write(`${outD}/strat.svg`, svgWrap(v, s)); console.log("strat done"); } // ===== B. a nuclear exchange at continent scale: fallout as a hex field ===== if (which.includes("nuke")) { const v = view([-5, 43.2, 33, 60.5], 1600, 1000); let s = politicalBase(v, { regionsOf: EUR }); // sources: the publicly named sharing bases (100 kt surface, assumed) and an illustrative cloud of strikes on forces const src: { lon: number; lat: number; kt: number }[] = bases.slice(0, 5).map((b) => ({ lon: b.lon, lat: b.lat, kt: 100 })); let rng = 11; const rnd = () => ((rng = (rng * 16807) % 2147483647) / 2147483647); for (let i = 0; i < 70; i++) src.push({ lon: 15 + rnd() * 13, lat: 50 + rnd() * 6.5, kt: 10 + rnd() * 40 }); for (let i = 0; i < 40; i++) src.push({ lon: 27 + rnd() * 6, lat: 52 + rnd() * 5, kt: 10 + rnd() * 40 }); // wind field: from the west-south-west, veering with latitude const windTo = (lat: number) => 68 + (lat - 50) * 2.2; // degrees from north, blowing towards const dose = (lon: number, lat: number) => { let d = 0; for (const q of src) { const kx = 111.32 * Math.cos((q.lat * Math.PI) / 180); const dx = (lon - q.lon) * kx, dy = (lat - q.lat) * 110.57; const a = (windTo(q.lat) * Math.PI) / 180; const along = dx * Math.sin(a) + dy * Math.cos(a), across = dx * Math.cos(a) - dy * Math.sin(a); if (along < -15) continue; // 48 h outdoor dose along the plume axis, fitted to the 100 kt H+1 contours of v1-nuclear // (1000/100/10/1 rad/h at 9/32/80/150 km, times ~5 for 48 h): a power law, scaled by yield const s = Math.pow(q.kt / 100, 0.45), al = Math.max(along, 0) / s, wd = (1.5 + 0.1 * al) * s; d += 8000 * Math.pow(al + 3, -2.3) * Math.exp(-((across / wd) ** 2)) * (along < 0 ? Math.exp(along / 3) : 1); } return d; // Gy in the first 48 h outdoors, illustrative scale }; const bands = [ { min: 10, col: "#c9262a" }, { min: 1, col: "#ec6a2c" }, { min: 0.1, col: "#f2c14c" }, { min: 0.02, col: "#9cc7a8" } ]; const R = 4.5; let hexes = ""; const byBand: string[] = bands.map(() => ""); for (const [x, y] of hexCentres(v.W, v.H, R)) { const [lon, lat] = v.inv(x, y); let d = dose(lon, lat); for (let k = 0; k < 6; k++) { const a = (k * Math.PI) / 3; const [l2, b2] = v.inv(x + Math.cos(a) * R * 0.6, y + Math.sin(a) * R * 0.6); d = Math.max(d, dose(l2, b2)); } const bi = bands.findIndex((b) => d >= b.min); if (bi >= 0) byBand[bi] += hexPath(x, y, R - 0.6); } bands.forEach((b, i) => { hexes += ``; }); s += `${hexes}`; for (const q of src) { const [x, y] = v.P(q.lon, q.lat); s += ``; } for (const b of bases.slice(0, 5)) { const [x, y] = v.P(b.lon, b.lat); s += `${b.name}`; } s += capitals(v, 1.2e6, 0.85); // where you are: Groningen const [gx, gy] = v.P(6.567, 53.219); s += ``; // wind arrows for (const [lon, lat] of [[0, 47], [2, 55], [12, 45.5], [22, 58.6], [-2, 51]]) { const [x, y] = v.P(lon, lat); s += ``; } console.log("Groningen dose", dose(6.567, 53.219).toFixed(3), "Berlin", dose(13.4, 52.52).toFixed(2), "Warsaw", dose(21.0, 52.23).toFixed(2)); await Bun.write(`${outD}/nuke.svg`, svgWrap(v, s)); } // ===== C. a drone wave at night: regions light up by time to arrival ===== type Group = { id: string; t0: number; n: number; pts: number[][]; downed: number }; const SPEED = 170; // km/h, a slow one-way attack drone function posAt(g: Group, t: number): number[] | null { let dist = ((t - g.t0) / 60) * SPEED; if (dist < 0) return null; for (let i = 0; i < g.pts.length - 1; i++) { const L = kmBetween(g.pts[i], g.pts[i + 1]); if (dist <= L) { const f = dist / L; return [g.pts[i][0] + (g.pts[i + 1][0] - g.pts[i][0]) * f, g.pts[i][1] + (g.pts[i + 1][1] - g.pts[i][1]) * f]; } dist -= L; } return null; } function drawGroups(v: V, groups: Group[], now: number, horizon: number) { let s = ""; for (const g of groups) { // past let past = "", fut = "", cone = ""; for (let t = g.t0; t <= now; t += 4) { const p = posAt(g, t); if (!p) break; const [x, y] = v.P(p[0], p[1]); past += (past ? "L" : "M") + r1(x) + " " + r1(y); } const head = posAt(g, now); if (!head) continue; const left: string[] = [], right: string[] = []; let prev = head; for (let t = now; t <= now + horizon; t += 5) { const p = posAt(g, t); if (!p) break; const [x, y] = v.P(p[0], p[1]); fut += (fut ? "L" : "M") + r1(x) + " " + r1(y); const [px, py] = v.P(prev[0], prev[1]); const dx = x - px, dy = y - py, l = Math.hypot(dx, dy) || 1; const spread = v.kmPx(6 + (t - now) * 0.55, p[1]); left.push(`${r1(x - (dy / l) * spread)} ${r1(y + (dx / l) * spread)}`); right.unshift(`${r1(x + (dy / l) * spread)} ${r1(y - (dx / l) * spread)}`); prev = p; } if (left.length > 2) cone = `M${left.join("L")}L${right.join("L")}Z`; s += ``; s += ``; s += ``; // ETA ticks every 30 min for (let t = Math.ceil(now / 30) * 30; t <= now + horizon; t += 30) { const p = posAt(g, t); if (!p) break; const [x, y] = v.P(p[0], p[1]); const hh = Math.floor((22 * 60 + t) / 60) % 24, mm = (22 * 60 + t) % 60; s += `${String(hh).padStart(2, "0")}:${String(mm).padStart(2, "0")}`; } // interceptions along the past track for (let k = 1; k <= 3; k++) { const p = posAt(g, g.t0 + ((now - g.t0) * (0.35 + 0.2 * k))); if (!p) continue; const [x, y] = v.P(p[0], p[1]); s += ``; } // the head: a cluster const [hx, hy] = v.P(head[0], head[1]); s += ``; for (let k = 0; k < 7; k++) { const a = k * 2.4, rr = 3 + (k % 3) * 3.2; s += ``; } s += `${g.id} · ${g.n - g.downed}`; } return s; } function regionStates(regs: Region[], groups: Group[], now: number) { const st = new Map(); for (const r of regs) { let best = 1e9, wasIn = false; for (const g of groups) { for (let t = g.t0; t <= now + 180; t += 4) { const p = posAt(g, t); if (!p) break; if (inRegion(r, p[0], p[1])) { if (t <= now - 8) wasIn = true; else best = Math.min(best, Math.max(t - now, 0)); } } } if (best <= 0) st.set(r, { k: "now", eta: 0 }); else if (best <= 60) st.set(r, { k: "soon", eta: best }); else if (best <= 180) st.set(r, { k: "later", eta: best }); else if (wasIn) st.set(r, { k: "passed", eta: -1 }); } return st; } const STATE_COL = { now: "#d63a2f", soon: "#ef8a2e", later: "#d9c25a", passed: "#5a7f99" } as const; function fillRegions(v: V, st: Map) { let s = ""; for (const [r, x] of st) { const d = path(v, r.g, true, 0.8); s += ``; if (x.k === "passed") s += ``; } return s; } const drone: Group[] = [ { id: "Group A", t0: 30, n: 64, downed: 18, pts: [[30.5, 53.9], [23.8, 52.6], [19.0, 52.3], [14.5, 52.4], [11, 52.3], [7.5, 52.2], [5.5, 52.1]] }, { id: "Group B", t0: 60, n: 41, downed: 9, pts: [[29.5, 55.5], [26.0, 55.8], [24.0, 56.3], [21.5, 56.8], [18, 57.5], [14.5, 56.0], [11.5, 55.3]] }, { id: "Group C", t0: 0, n: 52, downed: 21, pts: [[31.0, 52.0], [24.0, 51.2], [21.0, 50.3], [18.0, 49.8], [15, 50.0], [12.5, 50.2]] }, { id: "Group D", t0: 75, n: 36, downed: 6, pts: [[31.5, 54.5], [27, 54.6], [23.0, 54.4], [19.5, 54.6], [15.5, 54.4], [12.5, 54.3], [10, 54.3]] }, ]; if (which.includes("drones")) { const v = view([4.5, 48.3, 33.5, 59.2], 1600, 1000); const now = 250; // 02:10 const regs = regionsOf(EUR); let s = ` `; s += politicalBase(v, { regionsOf: EUR }); const st = regionStates(regs, drone, now); s += fillRegions(v, st); // launch areas, broad and illustrative for (const [lon, lat, rx, ry] of [[30.7, 53.2, 70, 110], [30.0, 55.4, 55, 45]]) { const [x, y] = v.P(lon, lat); s += ``; } s += drawGroups(v, drone, now, 150); s += capitals(v, 1e6, 0.8); const counts: Record = { now: 0, soon: 0, later: 0, passed: 0 }; const names: Record = { now: [], soon: [], later: [], passed: [] }; for (const [r, x] of st) { counts[x.k]++; names[x.k].push(`${r.name} (${r.a3}${x.k === "soon" || x.k === "later" ? " " + x.eta + "m" : ""})`); } console.log("drone regions", JSON.stringify(counts), JSON.stringify(names)); for (const g of drone) { const p = posAt(g, now); console.log(g.id, p?.map((n) => n.toFixed(2))); } await Bun.write(`${outD}/drones.svg`, svgWrap(v, s)); } // ===== D. a phone: one person's view of a warning, the Netherlands ===== if (which.includes("phone")) { const v = view([3.3, 50.72, 7.5, 53.58], 780, 1180); const now = 0; const g: Group[] = [{ id: "Drones", t0: -60, n: 12, downed: 3, pts: [[10.2, 52.05], [7.4, 52.3], [5.9, 52.2], [4.6, 52.0]] }]; const regs = regionsOf(["NLD", "DEU", "BEL"]); let s = ``; s += `` + baseMap(v, { mute: 0.5, provinces: true }) + ``; const st = regionStates(regs, g, now); s += fillRegions(v, st); s += countryLines(v, ["NLD"], "#fd6012", 2.2); s += drawGroups(v, g, now, 120); s += placeBanners(v, cities, 9, (c) => banner(v, c, { small: true })); const [px, py] = v.P(5.969, 52.211); // Apeldoorn s += ``; for (const [r, x] of st) console.log("phone", r.name, x.k, x.eta); await Bun.write(`${outD}/phone.svg`, svgWrap(v, s)); } // ===== E. area statistics (CBS Kerncijfers wijken en buurten 2024, via PDOK's wijkenbuurten WFS) ===== // gem_stats.json: wijkenbuurten:gemeenten; buurt_apd.json: wijkenbuurten:buurten around Apeldoorn. Negative values are CBS's "missing" codes. const ok = (x: any) => typeof x === "number" && x >= 0; const O65 = [ { max: 18, col: "#3f6f78" }, { max: 21, col: "#6f9c8f" }, { max: 24, col: "#c9b46a" }, { max: 27, col: "#e08a4a" }, { max: 99, col: "#c8553d" } ]; const o65col = (v: number) => O65.find((c) => v < c.max)!.col; if (which.includes("areas")) { const gem = (await J("gem_stats.json")).features.filter((f: any) => f.properties.water !== "JA"); const v = view([3.25, 50.72, 7.3, 53.58], 1600, 1000); let s = ``; const landD = path(v, { type: "MultiPolygon", coordinates: landPolys }, true); s += ``; for (const f of gem) { const p = f.properties; const d = path(v, f.geometry, true, 0.5); s += ``; } const lakeD = lakes.features.map((f: any) => path(v, f.geometry, true)).join(""); s += ``; const pv = feats(provs, (p) => ["NLD"].includes(p.adm0_a3)).map((f: any) => path(v, f.geometry, false)).join(""); s += ``; s += countryLines(v, ["NLD"], "#fd6012", 2.5); // highlight Apeldoorn const ap = gem.find((f: any) => f.properties.gemeentenaam === "Apeldoorn"); s += ``; s += placeBanners(v, cities.filter((c) => c.lat > 50.7 && c.lat < 53.6 && c.lon > 3.3 && c.lon < 7.3), 14, (c) => banner(v, c, { small: true })); await Bun.write(`${outD}/areas.svg`, svgWrap(v, s)); const vals = gem.map((f: any) => f.properties.percentagePersonen65JaarEnOuder).filter(ok); console.log("areas", gem.length, "classes", O65.map((c, i) => vals.filter((x: number) => x < c.max && (i === 0 || x >= O65[i - 1].max)).length).join(",")); const pick = ["Apeldoorn", "Utrecht", "Groningen", "Amsterdam"].map((n) => { const p = gem.find((f: any) => f.properties.gemeentenaam === n).properties; return `${n}: 65+ ${p.percentagePersonen65JaarEnOuder}% alone ${p.percentageEenpersoonshuishoudens}% GP ${p.huisartsenpraktijkGemiddeldeAfstandInKm} solar ${p.percentageWoningenMetZonnestroom} green ${p.afstandTotOpenbaarGroenTotaal}`; }); console.log(pick.join("\n")); } if (which.includes("apd")) { const bu = (await J("buurt_apd.json")).features.filter((f: any) => f.properties.gemeentecode === "GM0200" && f.properties.water !== "JA"); const v = view([5.905, 52.175, 6.035, 52.245], 780, 1180); let s = ``; for (const f of bu) { const p = f.properties; const d = path(v, f.geometry, true, 0.4); s += ``; } const bs = bu.find((f: any) => f.properties.buurtnaam === "Binnenstad"); s += ``; const taken: number[][] = []; for (const f of bu) { const p = f.properties; const g = f.geometry; const ring = (g.type === "Polygon" ? g.coordinates[0] : g.coordinates[0][0]); let x = 0, y = 0; for (const [lo, la] of ring) { x += lo; y += la; } const [px, py] = v.P(x / ring.length, y / ring.length); if (px < 60 || px > v.W - 60 || py < 30 || py > v.H - 20 || p.aantalInwoners < 2500) continue; if (taken.some(([tx, ty]) => Math.abs(tx - px) < 120 && Math.abs(ty - py) < 26)) continue; taken.push([px, py]); s += `${p.buurtnaam.replace(/&/g, "&")}`; } const [px, py] = v.P(5.962, 52.2115); s += ``; await Bun.write(`${outD}/apd.svg`, svgWrap(v, s)); const p = bs.properties; console.log("Binnenstad", JSON.stringify({ n: p.aantalInwoners, o65: p.percentagePersonen65JaarEnOuder, alone: p.percentageEenpersoonshuishoudens, gp: p.huisartsenpraktijkGemiddeldeAfstandInKm, sup: p.groteSupermarktGemiddeldeAfstandInKm, green: p.afstandTotOpenbaarGroenTotaal, solar: p.percentageWoningenMetZonnestroom, rent: p.percentageHuurwoningen })); const all = bu.map((f: any) => f.properties).filter((q: any) => q.aantalInwoners >= 50); console.log("apd buurten drawn", bu.length, "with 50+ people", all.length); } console.log("all done");