a DSL to do numerical control for CNC machines

john ac9d0daf1d fix header for link 1 month ago
examples bafa44dae8 initial stuff 5 months ago
.gitignore 9eec99b9d9 gitignore 5 months ago
LICENSE d4fe8a89a8 Initial commit 5 months ago
README.md ac9d0daf1d fix header for link 1 month ago
cylinder.jsnc f6566e0fb0 lots of stuff 3 months ago
gcode.json bafa44dae8 initial stuff 5 months ago
index.html bafa44dae8 initial stuff 5 months ago
index.js 26c7ee709e delete the old code when we emit 1 month ago
jsconfig.json 89aa3c3e31 a bunch of stuff but mostly adding letters 1 month ago
stdPaths.jsnc 33b9cf456a added newline, tweaked spacing 1 month ago


JSNC (javascript numerical control)

JSNC is a small DSL and library for generating gcode for CNC machines. It allows you to use all the power of a scripting language to create otherwise difficult toolpaths. It is inspired in part by OpenSCAD.


  • all of javascript! JSNC is basically just a handful of preprocess steps that convert your jsnc code into vanila javascript which gets (gasp) eval'd. So any neato feature in JS is yours for the taking
  • A small (but growing) standard library of shapes/paths and functions.
  • It's own font! I've designed a font so you can write your herat out. Currently only supports A-Z . space and newlines.
  • Emiting gcode is super clean. any time a gcode is hit in the flow of your program a matching code is push onto the stack of gcodes to be emitted
  • cleans excessive G90 and G91 codes
    • these codes are used to switch between absolute and relative mode
    • When one is found it is checked against the last known state so that extra calls aren emited in the final gcode

Try it out!

Code Sample

Here is a code that generates a Lorentz Attractor. goodluck modeling THAT in autocad :P

let x = 0.01;
let y = 0.01;
let z = 0.01;

let o = 10;
let p = 28;
let B = 8 / 3;
let dt = 0.001;
let scale = 2;

G0 Z0 F1300

for (let i = 0; i < 100000; i++) {
  const dx = o * (y - x);
  const dy = x * (p - z) - y;
  const dz = x * y - B * z;

  x += dx * dt;
  y += dy * dt;
  z += dz * dt;

  G0 X${trnc(x)*scale} Y${trnc(y)*scale}

function trnc(v){
  return Math.round(v*1000)/1000

G0 Z1