Skip to content

Instantly share code, notes, and snippets.

@ryanthejuggler
Created February 6, 2014 02:25
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 ryanthejuggler/8837407 to your computer and use it in GitHub Desktop.
Save ryanthejuggler/8837407 to your computer and use it in GitHub Desktop.
G-code test generator
// usage: node testgen.js > myFile.g
// alter the below variables to taste!
var ORIGIN = [0,0];
var EXTENT = 90;
var NUM_LOOPS = 20;
var POINTS_PER_LOOP = 100;
var SPEED=20000;
var MAX_HEIGHT=250;
var i, theta, r, h;
console.log("G4 P5000");
console.log("G28");
console.log("G1 F"+SPEED);
for(i=0;i<NUM_LOOPS;i+=(1/POINTS_PER_LOOP)){
theta = 2*i*Math.PI;
r = EXTENT*(1-i/NUM_LOOPS);
h = MAX_HEIGHT*i/NUM_LOOPS;
console.log("G1 X"+(ORIGIN[0]+Math.cos(theta)*r)
+" Y"+(ORIGIN[1]+Math.sin(theta)*r)
+" Z"+h);
}
console.log("G28");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment