Initial
This commit is contained in:
33
tools/render-svg.mjs
Normal file
33
tools/render-svg.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
/* 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;
|
||||
}
|
||||
|
||||
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)`);
|
||||
Reference in New Issue
Block a user