Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created June 25, 2022 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hermann-SW/475a08756c583ea98e5086f990265b52 to your computer and use it in GitHub Desktop.
Save Hermann-SW/475a08756c583ea98e5086f990265b52 to your computer and use it in GitHub Desktop.
OpenSCAD external NodeJS animation demo
var fs = require("fs");
var writer;
function wait(ms) {
return new Promise(function (resolve) {
setTimeout(resolve, ms);
});
}
function rad2deg(r) {
return r / Math.PI * 180;
}
function out(x) {
return (typeof(x) === 'object') ? JSON.stringify(x) : x;
}
function wlog(...s) {
var i;
writer.write(out(s[0]));
for(i=1; i<s.length; i = i + 1) {
writer.write(" " + out(s[i]));
}
writer.write("\n");
}
async function amain() {
var i = 0;
var coords=[[0,0,0],[1,0,0],[0,2,0],[0,0,3]];
var col=[[1,1,1],[0,1,0]];
while (true) {
writer = fs.createWriteStream('x.scad');
wlog("$vpr = [",-rad2deg(-Math.PI/4),",0,",
-rad2deg(Math.atan2(-0.5, 0.5)),"];");
wlog("$fn = 25;");
wlog("$vpt = [0,0,0];");
wlog("module vertex(v, c) { color(c) translate(v) sphere(0.5); }");
wlog("vertex(", coords[i%4], ",", col[i%2], ");");
writer.close();
await wait(1200);
i = i + 1;
}
}
amain();
@Hermann-SW
Copy link
Author

Hermann-SW commented Jun 25, 2022

So all you need to do after running "nodejs wlog.js" is to open "x.scad" in OpenSCAD:
https://forums.raspberrypi.com/viewtopic.php?p=2014370#p2014370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment