Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Functions to generate GCode, suitable for being run on a penplotter.
(image code)
>>>
:{
D.haddockRender "Draw/Plotting/example.svg" 300 200 $ \_ -> do let haskellLogo' = transform mirrorYCoords haskellLogo geometry = transform (transformBoundingBox haskellLogo' (shrinkBoundingBox 10 [zero, Vec2 300 200]) def) haskellLogo' plotSettings = def { _canvasBoundingBox = Just (boundingBox [zero, Vec2 300 200]) } plotResult = runPlot def $ do for_ geometry $ \logoPart -> plot logoPart _plotPreview plotResult :} Generated file: size 10KB, crc32: 0x1e175925
Synopsis
- data Plot a
- runPlot :: PlottingSettings -> Plot a -> RunPlotResult
- data GCode
- writeGCodeFile :: FilePath -> RunPlotResult -> IO ()
- renderPreview :: FilePath -> Double -> RunPlotResult -> IO ()
- data RunPlotResult = RunPlotResult {
- _plotGCode :: [GCode]
- _plotPreview :: Render ()
- _plotBoundingBox :: BoundingBox
- _totalBoundingBox :: BoundingBox
- _plotInternals :: TinkeringInternals
- data PlottingSettings = PlottingSettings {
- _feedrate :: Double
- _zTravelHeight :: Double
- _zDrawingHeight :: Double
- _zLoweringFeedrate :: Maybe Double
- _finishMove :: Maybe FinishMove
- _previewDrawnShapesBoundingBox :: Bool
- _canvasBoundingBox :: Maybe BoundingBox
- _previewPenWidth :: Double
- _previewPenColor :: Color Double
- _previewPenTravelColor :: Maybe (Color Double)
- _previewDecorate :: Bool
- data FinishMove
- data TinkeringInternals = TinkeringInternals {}
- data PlottingWriterLog = PlottingWriterLog {
- _plottedGCode :: DList GCode
- _penTravelDistance :: !Double
- _elementsDrawn :: !Int
- _plottingCairoPreview :: Render ()
- data PlottingState = PlottingState {
- _penState :: !PenState
- _penXY :: !Vec2
- _drawingDistance :: !Double
- _drawnBoundingBox :: !BoundingBox
- renderGCode :: [GCode] -> Text
- class Plotting a where
- repositionTo :: Vec2 -> Plot ()
- lineTo :: Vec2 -> Plot ()
- clockwiseArcAroundTo :: Vec2 -> Vec2 -> Plot ()
- counterclockwiseArcAroundTo :: Vec2 -> Vec2 -> Plot ()
- previewCanvas :: Plot ()
- pause :: PauseMode -> Plot ()
- data PauseMode
- withFeedrate :: Double -> Plot a -> Plot a
- withDrawingHeight :: Double -> Plot a -> Plot a
- drawingDistance :: Plot Double
- block :: Plot a -> Plot a
- comment :: Text -> Plot ()
- penDown :: Plot ()
- penUp :: Plot ()
- gCode :: [GCode] -> Plot ()
- minimizePenHovering :: Sequential vector => Set (vector Vec2) -> [Vector Vec2]
- minimizePenHoveringBy :: Ord a => MinimizePenHoveringSettings a -> Set a -> [a]
- data MinimizePenHoveringSettings a = MinimizePenHoveringSettings {
- _getStartEndPoint :: a -> (Vec2, Vec2)
- _flipObject :: Maybe (a -> a)
- _mergeObjects :: Maybe (a -> a -> Maybe a)
Plot
type
Instances
Applicative Plot Source # | |
Functor Plot Source # | |
Monad Plot Source # | |
MonadReader PlottingSettings Plot Source # | |
Defined in Draw.Plotting ask :: Plot PlottingSettings # local :: (PlottingSettings -> PlottingSettings) -> Plot a -> Plot a # reader :: (PlottingSettings -> a) -> Plot a # | |
MonadState PlottingState Plot Source # | |
Defined in Draw.Plotting get :: Plot PlottingState # put :: PlottingState -> Plot () # state :: (PlottingState -> (a, PlottingState)) -> Plot a # |
runPlot :: PlottingSettings -> Plot a -> RunPlotResult Source #
Run the Plot
to easily generate the resulting GCode file. For convenience, this also generates a Cairo-based preview of the geometry.
let plotResult =runPlot
settings bodywriteGCodeFile
"output.g" plotResultrenderPreview
"output.png" 3 plotResult
writeGCodeFile :: FilePath -> RunPlotResult -> IO () Source #
:: FilePath | |
-> Double | Output resolution in px/mm |
-> RunPlotResult | |
-> IO () |
data RunPlotResult Source #
Result of runPlot
; unifies convenience API and internals for tinkering.
RunPlotResult | |
|
data PlottingSettings Source #
PlottingSettings | |
|
Instances
Show PlottingSettings Source # | |
Defined in Draw.Plotting showsPrec :: Int -> PlottingSettings -> ShowS # show :: PlottingSettings -> String # showList :: [PlottingSettings] -> ShowS # | |
Default PlottingSettings Source # | |
Defined in Draw.Plotting | |
Eq PlottingSettings Source # | |
Defined in Draw.Plotting (==) :: PlottingSettings -> PlottingSettings -> Bool # (/=) :: PlottingSettings -> PlottingSettings -> Bool # | |
MonadReader PlottingSettings Plot Source # | |
Defined in Draw.Plotting ask :: Plot PlottingSettings # local :: (PlottingSettings -> PlottingSettings) -> Plot a -> Plot a # reader :: (PlottingSettings -> a) -> Plot a # |
data FinishMove Source #
Command to issue after all drawing is finished
FinishWithG28 | G28: go to predefined position |
FinishWithG30 | G30: go to predefined position |
FinishTopRight | Move to the top right of the union of drawn and canvas |
Instances
Show FinishMove Source # | |
Defined in Draw.Plotting showsPrec :: Int -> FinishMove -> ShowS # show :: FinishMove -> String # showList :: [FinishMove] -> ShowS # | |
Eq FinishMove Source # | |
Defined in Draw.Plotting (==) :: FinishMove -> FinishMove -> Bool # (/=) :: FinishMove -> FinishMove -> Bool # | |
Ord FinishMove Source # | |
Defined in Draw.Plotting compare :: FinishMove -> FinishMove -> Ordering # (<) :: FinishMove -> FinishMove -> Bool # (<=) :: FinishMove -> FinishMove -> Bool # (>) :: FinishMove -> FinishMove -> Bool # (>=) :: FinishMove -> FinishMove -> Bool # max :: FinishMove -> FinishMove -> FinishMove # min :: FinishMove -> FinishMove -> FinishMove # |
Raw GCode handling
data TinkeringInternals Source #
TinkeringInternals | |
|
data PlottingWriterLog Source #
PlottingWriterLog | |
|
Instances
Monoid PlottingWriterLog Source # | |
Defined in Draw.Plotting | |
Semigroup PlottingWriterLog Source # | |
Defined in Draw.Plotting (<>) :: PlottingWriterLog -> PlottingWriterLog -> PlottingWriterLog # sconcat :: NonEmpty PlottingWriterLog -> PlottingWriterLog # stimes :: Integral b => b -> PlottingWriterLog -> PlottingWriterLog # |
data PlottingState Source #
PlottingState | |
|
Instances
Show PlottingState Source # | |
Defined in Draw.Plotting showsPrec :: Int -> PlottingState -> ShowS # show :: PlottingState -> String # showList :: [PlottingState] -> ShowS # | |
Eq PlottingState Source # | |
Defined in Draw.Plotting (==) :: PlottingState -> PlottingState -> Bool # (/=) :: PlottingState -> PlottingState -> Bool # | |
Ord PlottingState Source # | |
Defined in Draw.Plotting compare :: PlottingState -> PlottingState -> Ordering # (<) :: PlottingState -> PlottingState -> Bool # (<=) :: PlottingState -> PlottingState -> Bool # (>) :: PlottingState -> PlottingState -> Bool # (>=) :: PlottingState -> PlottingState -> Bool # max :: PlottingState -> PlottingState -> PlottingState # min :: PlottingState -> PlottingState -> PlottingState # | |
MonadState PlottingState Plot Source # | |
Defined in Draw.Plotting get :: Plot PlottingState # put :: PlottingState -> Plot () # state :: (PlottingState -> (a, PlottingState)) -> Plot a # |
Plotting
shapes
class Plotting a where Source #
Draw a shape by lowering the pen, setting the right speed, etc. The specifics
are defined in the configuration given in runPlot
, or by the various utility
functions such as withFeedrate
or withDrawingHeight
Instances
Plotting Bezier Source # | FluidNC doesn’t support G05, so we approximate Bezier curves with line pieces.
We use the naive Bezier interpolation |
Plotting BoundingBox Source # | Trace the bounding box without actually drawing anything to estimate result size |
Defined in Draw.Plotting plot :: BoundingBox -> Plot () Source # | |
Plotting Circle Source # | |
Plotting Ellipse Source # | Approximation by a number of points |
Plotting Line Source # | |
Plotting Polygon Source # | |
Plotting Polyline Source # | |
(Functor f, Sequential f, Plotting a) => Plotting (f a) Source # | Draw each element (in order) |
Defined in Draw.Plotting | |
(Plotting a, Plotting b) => Plotting (a, b) Source # | Draw each element (in order) |
Defined in Draw.Plotting | |
(Plotting a, Plotting b, Plotting c) => Plotting (a, b, c) Source # | Draw each element (in order) |
Defined in Draw.Plotting | |
(Plotting a, Plotting b, Plotting c, Plotting d) => Plotting (a, b, c, d) Source # | Draw each element (in order) |
Defined in Draw.Plotting | |
(Plotting a, Plotting b, Plotting c, Plotting d, Plotting e) => Plotting (a, b, c, d, e) Source # | Draw each element (in order) |
Defined in Draw.Plotting |
Plotting primitives
repositionTo :: Vec2 -> Plot () Source #
Quick move for repositioning (without drawing).
Arc interpolation, clockwise
counterclockwiseArcAroundTo Source #
Arc interpolation, counterclockwise
previewCanvas :: Plot () Source #
Trace the plotting area to preview the extents of the plot, and wait for confirmation. Useful at the start of a plot.
PauseUserConfirm | Wait until user confirmation, e.g. in a web UI or with a button. (M0/Pause) |
PauseSeconds Double | Wait for a certain time (G4/Dwell) |
withDrawingHeight :: Double -> Plot a -> Plot a Source #
Locally adapt the z drawing height (e.g. for changing pen pressure)
drawingDistance :: Plot Double Source #
Distance drawn so far.
One use case is adding a pause when a pencil needs sharpening again.
File structure
block :: Plot a -> Plot a Source #
Group the commands generated by the arguments in a block. This is purely cosmetical for the generated GCode.
Raw G-Code
If the pen is up, lower it to drawing height. Do nothing if it is already lowered.
If the pen is down, lift it to travel height. Do nothing if it is already lifted.
Utilities
:: Sequential vector | |
=> Set (vector Vec2) | Elements of this set will be sorted in optimized order. The elements themselves remain untouched. |
-> [Vector Vec2] |
Sort a collection of polylines so that between each line pair, we only do the shortest move. This is a local solution to what would be TSP if solved globally. Better than nothing I guess, although this algorithm here is \(\mathcal O(n^2)\).
minimizePenHoveringBy :: Ord a => MinimizePenHoveringSettings a -> Set a -> [a] Source #
Similar to minimizePenHovering
, but for arbitrary objects with a given start and end point.
data MinimizePenHoveringSettings a Source #
MinimizePenHoveringSettings | |
|