// slightly cleaned up from harvey moon's drawing machine // http://www.kickstarter.com/projects/notever/the-drawing-machine/posts // http://unanything.com/ // https://files.me.com/sami6877/wg01bu // http://www.creativeapplications.net/maxmsp/drawing-machine-maxmsp-processing/ // rtwomey@u.washington.edu // Key 1 = 0,0 // Key 2 = width,0 // Key 3 = width,height // Key 4 = 0,height // Key S = stop // Key G = go LineToGo toGoArray; Bot Machine; OutputImage Photo; import processing.serial.*; // serial communication import java.io.*; //Java import geomerative.*; // svg parsing //--------------------------------------------------- //Change these if you want. float multiplier = 0.125;// full step, 1/8 resolution. 1.0; // size multiplication boolean doSave=true; boolean timelapse = false; boolean servoOn = true; // draw with the servo control or not. boolean serialOn = true; //TURN SERIAL ON WITH 1 OFF WITH ANYTHING ELSE boolean printArray = false; boolean autoStop = true; boolean On = false;// USED SO THAT THE KEY 'S' AND 'G' START AND STOP THE DRAWING SEQUENCE, starts off to calibrate int xoffset = 0;//10845/2; // Ofset of x from left top corner int yoffset = 0;//6920/4;//3750; // Ofset of y from left top corner // page width in step units int PAGEW = 10252; int PAGEH = 6990; //--------------------------------------------------- PVector Current; PVector lastOld; boolean jumpFlag = true; boolean atPoint = true; // if the arduino returns that it is at the point, turn true. float onScreenScale=0.1667;//0.10; RShape grp; RPoint[][] pointPaths; int j = 0; int i = 0; void setup() { Photo = new OutputImage(); //---------------------------------------------------------------------------------- // size(7200, 4800); //size(11000, 7500); //size(1000, 800); size(1708, 1165); RG.init(this); RG.ignoreStyles(true); //RG.setPolygonizer(RG.ADAPTATIVE); RG.setPolygonizer(RG.UNIFORMLENGTH); //grp = RG.loadShape("treemesh.svg"); //grp = RG.loadShape("exploded_pocket_knife_simplified.svg"); //grp = RG.loadShape("cal39.svg"); grp = RG.loadShape("blood_storage_container_and_methods_fig3.svg"); //grp = RG.loadShape("box.svg"); grp.centerIn(g, 0, 0, 0); float grpW = grp.getWidth(); float grpH = grp.getHeight(); // xoffset=round(grpW/2); // yoffset=round(grpH/2); println(grpW+" width "+grpH+ "height"); println(grp.getX()+" "+grp.getY()); pointPaths = grp.getPointsInPaths(); //---------------------------------------------------------------------------------- background(255); toGoArray = new LineToGo(); //start the array line Machine = new Bot(this); Current = new PVector(0, 0, 0); lastOld = new PVector(0, 0); //grp.draw(); // delay(3000); //background(255); }//void setup void keyPressed() { if (key == 'a') { atPoint =true; } if (key == 'g') { // g key will start the movement. On = true; autoStop = true; } if (key == 's') { //s key will stop the movement autoStop = false; On = false; } if (key == ' ') { background(255); } if (key== 'f') { stroke( 120 ); strokeWeight( 3 ); rect(0, 0, grp.getWidth()*onScreenScale, grp.getHeight()*onScreenScale); } if (!On) { switch(key) { case '1': Machine.sendVal(0, 0, 0); //move to the top left corner of the drawing area break; case '2': Machine.sendVal(PAGEW, 0, 0); //move to the top right corner of the drawing area break; case '3': Machine.sendVal(PAGEW, PAGEH, 0); //move to the bottom right corner of the drawing area break; case '4': Machine.sendVal(0, PAGEH, 0); //move to the bottom left corner of the drawing area break; } //switch 1-4 keys if ((key == 'a')||(key == 'z')||(key == 's')||(key == 'x')) {// ||(key == '-')||(key == '+')) { Machine.DirectCommand(str(key)); } // matches a correct command } // not on; } //end keyPressed void draw() { Machine.update(); //checks for new point reached toGoArray.update(); // check for atPoint, and send new value stroke( 120 ); strokeWeight( 3 ); fill( 220 ); //grp.draw(); if (On && (i < pointPaths.length)) { // PVector out = new PVector(-width/2, -height/2); //---------------------------- //println("point#: " + j + " / " + pointPaths[i].length); //println("path#: " + i + "/ " + pointPaths.length); if (j < pointPaths[i].length) { // count through each point in path Current.set(pointPaths[i][j].x, pointPaths[i][j].y, 1); // print("real xy : "); // println(Current.x + "," + Current.y); // print("point at: "); // print (Current.x + width/2 + out.x); // print(','); // println(Current.x + height/2 + out.y); // println("_________________________"); if (jumpFlag) { Current.z = 0; jumpFlag = false; } //toGoArray.addToArray(Current.x + width/2 + out.x, Current.y +height/2 + out.y, Current.z); // add a new point to the array toGoArray.addToArray(Current.x+xoffset, Current.y+yoffset, Current.z); // add a new point to the array Photo.addCount(); // adds a count to the save counter and total found points j++; //advance to next point in path } // each point in path if (j == pointPaths[i].length) { // if j has reached the last point in path i j = 0; //reset j for next path jumpFlag = true; //lift pen i++; //advance to next path println("moved to next path"); println("path#: " + i + "/ " + pointPaths.length); } // at last point in path } // end drawing paths }//path had points