Created
June 25, 2022 12:40
-
-
Save Hermann-SW/475a08756c583ea98e5086f990265b52 to your computer and use it in GitHub Desktop.
OpenSCAD external NodeJS animation demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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