-- Implicit CAD. Copyright (C) 2011, Christopher Olah (chris@colah.ca) -- Released under the GNU GPL, see LICENSE module Graphics.Implicit.Export.PolylineFormats where import Graphics.Implicit.Definitions svg polylines = text where -- SVG is stupidly laid out... (0,0) is the top left corner (xs, ys) = unzip (concat polylines) (minx, maxy) = (minimum xs, maximum ys) transform (x,y) = (x-minx, maxy - y) polylines2 = map (map transform) polylines svglines = concat $ map (\line -> " " " ++ show x ++ "," ++ show y) line) ++ "\" style=\"stroke:rgb(0,0,255);stroke-width:1;fill:none;\"/> \n" ) polylines2 text = " \n" ++ svglines ++ " " hacklabLaserGCode polylines = text where gcodeHeader = "(generated by ImplicitCAD, based of hacklab wiki example)\n" ++"M63 P0 (laser off)\n" ++"G0 Z0.002 (laser off)\n" ++"G21 (units=mm)\n" ++"F400 (set feedrate)\n" ++"M3 S1 (enable laser)\n" ++"\n" gcodeFooter = "M5 (disable laser)\n" ++"G00 X0.0 Y0.0 (move to 0)\n" ++"M2 (end)" gcodeXY :: ℝ2 -> [Char] gcodeXY (x,y) = "X"++ show x ++" Y"++ show y interpretPolyline (start:others) = "G00 "++ gcodeXY start ++ "\n" ++ "M62 P0 (laser on)\n" ++ concat (map (\p -> "G01 " ++ (gcodeXY p) ++ "\n") others) ++ "M63 P0 (laser off)\n\n" text = gcodeHeader ++ (concat $ map interpretPolyline polylines) ++ gcodeFooter