const { load } = require("@alex.garcia/observable-prerender"); const { Cluster } = require("puppeteer-cluster"); const fs = require("fs"); const outputFolder = 'clusteroutput8' const howManyArts = 72*2 const maxConcurrency = 20 const notebookId = "@enjalot/deconstructed-disjoint-force-directed-graph" const cells = [ "onions", "ticks", "linkDistance", "xStrength", "yStrength", "onionOpacity", "width", "height"] async function main() { try { fs.mkdirSync(outputFolder) } catch(e) {} const cluster = await Cluster.launch({ concurrency: Cluster.CONCURRENCY_CONTEXT, maxConcurrency, }); await cluster.task(async (params) => { page = params.page let id = params.data.notebook let i = params.data.index console.log("working on ", id, i, params.data) const notebook = await load(id, cells, { page }); // await notebook.redefine("ticks", i); await notebook.redefine("ticks", 20); await notebook.redefine("xStrength", params.data.xStrength); await notebook.redefine("yStrength", params.data.yStrength); await notebook.redefine("linkDistance", params.data.linkDistance); await notebook.redefine("manyBodyStrength", params.data.manyBodyStrength); await notebook.redefine("onionOpacity", 0.03); // let sim = await notebook.value("deconstructed") await notebook.screenshot("onions", `${outputFolder}/screenshot-${("000" + i).slice(-3)}.png`); console.log("saved", i) // await notebook.screenshot("chart", `${notebookId}.png`.replace("/", "_")); }); let arts = Array.from({length:howManyArts}).map((d,i) => i) for await (let i of arts) { cluster.queue({ notebook: notebookId, index: i, linkDistance: 30, manyBodyStrength: -30, xStrength: 0.1 + 0.15 * Math.sin(i/howManyArts * Math.PI), yStrength: 0.3 - 0.17 * Math.sin(i/howManyArts * Math.PI), // manyBodyStrength: -100 + i/howManyArts * 95 // linkDistance: 5 + i/howManyArts * 55 }); } await cluster.idle(); console.log(`ffmpeg -framerate 24 -i ${outputFolder}/screenshot-%03d.png -c:v libx264 -pix_fmt yuv420p ${outputFolder}.mp4; `) await cluster.close(); console.log("exit") process.exit() } main();