// 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 // Keys 5-8, corners of svg image // Key 0 = Home // Key H = home device // Key h = set origin and init coords. // 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 //--------------------------------------------------- // physical setup of plotters float MOTORSEP = 96.0; // how far apart are the two pulley lines float PLOTRAD = 2.51557; // page size and location relative to plotter setup float PAGEW = 44.0; float PAGEH = 30.0; float PAGE0X = (MOTORSEP-PAGEW)/2.0; float PAGE0Y = 50.0;//12.0;//40.0; // output settings float PPI = 90.0; // SVG (Pt) to plotter space (inch) coordinate conversion float multiplier = 1.0; // scale output? // onscreen display settings int windowW = 1400; float onScreenScale=windowW/(PAGEW*PPI); int windowH = int((PAGEH*PPI)*onScreenScale); // configuration boolean doSave=true; boolean timelapse = false; boolean servoOn = false; // 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; float FASTFEED = 150.0;//200.0; float SLOWFEED = 20.0;//15.0; //----------------------------------- // state variables boolean On = false;// USED SO THAT THE KEY 'S' AND 'G' START AND STOP THE DRAWING SEQUENCE, starts off to calibrate //boolean homed = false; PVector Current; PVector lastOld; boolean jumpFlag = true; boolean atPoint = true; // if the arduino returns that it is at the point, turn true. boolean atHome=true; //----------------------------------- // image file setup and coordinates RShape grp; float grpW, grpH, grpX, grpY; RPoint[][] pointPaths; // global counters int j = 0; int i = 0; // ---------------------------------- // for sorting paths class Path { int num; boolean flipped; Path(int _num, boolean _flipped) { num=_num; _flipped=flipped; } } Path[] paths; int currpath=0; int currpoint=0; int pointinc=1; int stoppoint; //------------------------------------ // main program // void setup() { PFont font; // The font must be located in the sketch's // "data" directory to load successfully font = loadFont("Serif-24.vlw"); textFont(font, 12); Photo = new OutputImage(); size(windowW, windowH); 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("/Users/rtwomey/Documents/exploded_pocket_knife.svg"); //grp = RG.loadShape("/Users/rtwomey/Documents/eye nerves outline.svg"); grp = RG.loadShape("/Users/rtwomey/Documents/sign of the snake.svg"); //grp = RG.loadShape("cal39.svg"); //grp = RG.loadShape("/Users/rtwomey/Documents/blood_storage_container_and_methods_fig3.svg"); //grp = RG.loadShape("slit lamp diagram.svg"); //grp = RG.loadShape("/Users/rtwomey/Documents/rocking_horse.svg"); //grp = RG.loadShape("/Users/rtwomey/Documents/schechner_the_fan.svg"); //grp = RG.loadShape("/Users/rtwomey/Documents/bedroom_laurel_hatched_simplified.svg"); //grp = RG.loadShape("/Users/rtwomey/Documents/svgs/threshold_20_blur_hatch.svg"); //grp = RG.loadShape("/Users/rtwomey/Documents/ankle_brace.svg"); //grp = RG.loadShape("box.svg"); grp.centerIn(g, 0, 0, 0); grpW = grp.getWidth(); grpH = grp.getHeight(); grpX = grp.getX(); grpY = grp.getY(); print("width X height: "+grpW+" "+grpH); println(" (inches "+(grpW/PPI)+" "+(grpH/PPI)+")"); println("on screen scale: "+onScreenScale); println("grpX,Y "+grpX+" "+grpY); pointPaths = grp.getPointsInPaths(); println("image has "+pointPaths.length+" paths"); paths = new Path[pointPaths.length]; for (int i=0;i=pointPaths.length if (i 0) { pathUsed[testindex]=true; i=testindex; flipped=testflipped; count++; if (count>=pointPaths.length) done=true; } else { done=true; } } println("done sorting."); } // display the sorted plotting path on screen void drawSortedPointPaths() { float lastx=0, lasty=0; float xstart, ystart, xend, yend; for (int i=0; i