├── ContourGen ├── ContourGen.pde ├── buildData.pde ├── data │ └── kale.jpg ├── patterns.pde ├── sortData.pde └── writeData.pde └── README.md /ContourGen/ContourGen.pde: -------------------------------------------------------------------------------- 1 | //=============================================================================// 2 | // ContureGenerator 3 | // By Bjørn Karmann, 01.03.2016 4 | // www.bjoernkarmann.dk 5 | // 6 | //Note: The resolution has to work on width 7 | //and height. 8 | // 800mm width x 1000mm height allow a resolution 9 | //=============================================================================// 10 | 11 | PImage img; 12 | int number = 0; 13 | float res = 0; 14 | PVector[] dots; 15 | float[][] sorted; 16 | int[] done; 17 | boolean targetIs = false; 18 | int sortedLength = 0; 19 | int c = 0; 20 | 21 | //=============================================================================// 22 | // MACHINE SETTINGS // 23 | 24 | String file = "water-color6.jpg"; // file name (data folder) 25 | int threshold = 60; // max line (mm) 26 | int resolution = 350; // bedst result 27 | int paperW = 700; // mm paper width 28 | int paperH = 1000; // mm paper height 29 | int zHeight = 18; // mm (pen lift) 30 | int zTarget = -1; // mm 31 | float stopAt = 0.95; // 1 = finish drawing at 100% 32 | 33 | // EXAMPLE DRAW SETTINGS 34 | 35 | float penThickness = 0.005; // mm pen thikness 36 | boolean grid = false; // show grid of resolution 37 | int printSpeed = 10; // lines pr. ms for draw animation 38 | 39 | 40 | // // 41 | //=============================================================================// 42 | 43 | void setup() { 44 | background(255); 45 | frameRate(800); 46 | size(700, 900); 47 | res = int(height/resolution); 48 | println(res); 49 | threshold = 100; 50 | buildData(); 51 | if (grid == true) { 52 | grid(); 53 | } 54 | sortData(); 55 | writeData(); 56 | strokeWeight(penThickness); 57 | } 58 | 59 | void draw() { 60 | 61 | //=============================================================================// 62 | // EXAMPLE DRAW // 63 | 64 | int amount = int(sorted.length*stopAt); 65 | 66 | for (int i = 0; i<100; i++) { //print speed 67 | 68 | float x = sorted[c][0]; 69 | float y = sorted[c][1]; 70 | float distX = sorted[c][2]; 71 | float distY = sorted[c][3]; 72 | 73 | line(x, y, distX, distY); 74 | c++; 75 | } 76 | 77 | if(c >= amount){ 78 | println("Drawing finished!"); 79 | String[] fileList = split(file, '.'); // save jpg file 80 | saveFrame("gcode/"+fileList[0]+"/example_"+resolution+".jpg"); 81 | noLoop(); 82 | } 83 | } 84 | 85 | //=============================================================================// 86 | // SHOW RESOLUTION GRID // 87 | 88 | void grid() { 89 | 90 | stroke(240); 91 | for (int i = 0; iprosSteps){ 61 | print("/"); 62 | prosSteps += 4; 63 | } 64 | } 65 | println(); 66 | print("Lines skipped: "+skipLine); 67 | print("\t"); 68 | println("Threshold: "+threshold+"mm"); 69 | } -------------------------------------------------------------------------------- /ContourGen/writeData.pde: -------------------------------------------------------------------------------- 1 | PrintWriter output; 2 | 3 | void writeData() { 4 | String[] fileList = split(file, '.'); 5 | output = createWriter("gcode/"+fileList[0]+"/"+fileList[0]+"_"+resolution+".nc"); // nc for gcode file 6 | output.println("G0 Z"+zHeight); 7 | int amount = int(sorted.length*stopAt); 8 | for (int i = 0; i threshold){ // lift for travels 24 | output.println("G0 Z"+zHeight); 25 | output.println("G0"+" X"+x+" Y"+y); */ 26 | }else if(i==sorted.length-stopAt){ // lift when done and save file 27 | output.println("G0 Z"+zHeight); 28 | output.flush(); 29 | output.close(); // Finishes the file 30 | println("File saved: "+"gcode/"+fileList[0]+"/"+fileList[0]+"_"+resolution+".nc"); 31 | 32 | }else{ // print 33 | output.println("G0"+" X"+x+" Y"+y); // draw lines 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linePlotter_to_gCode 2 | A processing sketch that converts any image into a custom line trace and outputs gCode 3 | --------------------------------------------------------------------------------