xxxxxxxxxx
151
var dpi=96; // // Scale of the
var w=1;
var h=1;
var mm = 0.2645833333; // converting from px to mm
var spd=4000; // how fast the drawer will move
var Gcode=[]; // Gcode we will output
var pse="G4 P0.20000000298023224"; // Pause command
var xarr=[];
var yarr=[];
var centerx;
var centery;
var rad=350;
var numlines=90;
function setup() {
w=floor((dpi*225)/25.4);
h=floor((dpi*250)/25.4)
createCanvas(w, h);
// Initialize the Gcode
Gcode.push("M3\nG90\nG21\nG1 F10000");
GDraw();
}
// Inside this function is where we will draw our shape
function GDraw()
{
}
function mousePressed()
{
xarr.length=0;
yarr.length=0;
GoTo((width-mouseX)*mm, mouseY*mm);
xarr.push(mouseX);
yarr.push(mouseY);
}
function mouseReleased()
{
beginShape();
PenDown();
noFill();
for(var i=0; i<xarr.length; i++)
{
vertex(xarr[i], yarr[i]);
GoTo((width-xarr[i])*mm, yarr[i]*mm);
}
endShape();
PenUp();
}
function draw() {
//background(220);
if(mouseIsPressed)
{
if((mouseX !== xarr[xarr.length-1]) && (mouseY !== yarr[yarr.length-1]))
{
xarr.push(mouseX);
yarr.push(mouseY);
}
}
noFill();
beginShape();
for(var i=0; i<xarr.length; i++)
{
vertex(xarr[i], yarr[i]);
}
endShape();
}
function keyPressed()
{
Gcode.push("M3\n" + pse + "\nG1 X0 Y0\n");
m=minute();
save(Gcode, m+'.gcode');
}
// Draw a line
function Gline(x1,y1, x2, y2)
{
var cx1=x1*mm; // converted x from px to mm
var cy1=y1*mm; // Converted y from px to mm
var cx2=x2*mm;
var cy2=y2*mm;
// First we need to move to X1, Y1,
//Gcode.push("M3\n" + pse + "\nG1 F10000");
Gcode.push("G1 X" + cx1 + " Y" + cy1);
//Set pen down and set speed
Gcode.push("M5 S90\n" + pse + "\nG1 4000")
// Go to second point
Gcode.push("G1 X" + cx2 + " Y" + cy2);
// Raise Pen
Gcode.push("M3\n" + pse);
line(x1, y1, x2, y2);
// console.log(Gcode);
}
//Draw A circle
function GCircle(x,y, d)
{
var res=90; // How many lines to make the circle out of.
var offset=360/res;
// Start at the "top" of the circle;
var px=d/2* cos(radians(270)) + x;
var py=d/2* sin(radians(270)) + y;
GoTo(px*mm, py*mm);
PenDown();
for(var i=1; i<=res; i++)
{
px= d/2 * cos(radians((270+(i*offset)))) + x;
py= d/2 * sin(radians((270+(i*offset)))) + y;
//console.log(px,py);
GoTo(px*mm, py*mm);
}
PenUp();
noFill();
circle(x,y,d);
}
function PenUp()
{
Gcode.push("M3\n" + pse +"\nG10000");
}
function PenDown()
{
Gcode.push("M5 S90\n" + pse + "\nG1 4000");
}
function GoTo(xin,yin)
{
Gcode.push("G1 X" + xin + " Y" + yin);
}