42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
/* Render a scene to SVG from the CLI (shares the scene module).
|
|
Two modes:
|
|
node tools/render-svg.mjs --seed SEED [outfile] [sizePx] (seed → all params)
|
|
node tools/render-svg.mjs [preset] [seed] [outfile] (legacy preset mode)
|
|
*/
|
|
import { writeFileSync } from 'node:fs';
|
|
import { generateScene } from '../src/scene/scene.js';
|
|
import { renderSVG } from '../src/render/svgVector.js';
|
|
import { paramsFromSeed } from '../src/scene/params.js';
|
|
import { GROUPS, TOGGLES, FIXED, PRESETS } from '../src/ui/controls.js';
|
|
|
|
const argv = process.argv.slice(2);
|
|
let params, out, size = 4800;
|
|
|
|
if (argv[0] === '--seed') {
|
|
const seed = argv[1] || 'ENTROPY-001';
|
|
params = { ...FIXED, ...paramsFromSeed(seed) };
|
|
out = argv[2];
|
|
if (argv[3]) size = +argv[3];
|
|
} else {
|
|
const [preset, seed, o] = argv;
|
|
params = { ...FIXED, seed: seed || 'ENTROPY-001' };
|
|
for (const g of GROUPS) for (const c of g.controls) params[c.id] = c.value;
|
|
for (const t of TOGGLES) params[t.id] = t.value;
|
|
if (preset && PRESETS[preset]) Object.assign(params, PRESETS[preset]);
|
|
if (seed) params.seed = seed;
|
|
out = o;
|
|
}
|
|
|
|
// generic k=v overrides (e.g. diskBubbles=false shockStain=0.8)
|
|
for (const a of argv) {
|
|
if (!a.includes('=')) continue;
|
|
const [k, ...rest] = a.split('=');
|
|
const v = rest.join('=');
|
|
params[k] = v === 'true' ? true : v === 'false' ? false : (v.trim() !== '' && !isNaN(+v) ? +v : v);
|
|
}
|
|
|
|
const svg = renderSVG(generateScene(params), params, size);
|
|
const file = out || `/tmp/bc-${params.seed}.svg`;
|
|
writeFileSync(file, svg);
|
|
console.log(`SVG -> ${file} (${(svg.length / 1024).toFixed(0)} KB)`);
|