News for hackers. Stuff that matters.
Re:Show HN: Tool that turns your images into plotter-like li... by londons_explore on Thursday May 20, 2021 @05:12PM (#27227343)
It's just a list of X, Y coordinates...

An untested python one-liner:

    '\n'.join(["G0 X"+x+" Y"+y for x,y in coords])
Grab the code for homing and stuff from the start of another gcode file that works.
Re:Show HN: Tool that turns your images into plotter-like li... by eyegor on Thursday May 20, 2021 @05:48PM (#27227797)
Svg is typically a lot more complicated than coordinate points... https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Pa...
Re:Show HN: Tool that turns your images into plotter-like li... by paulgb on Friday May 21, 2021 @09:35AM (#27233788)
If you can use an editor like Inkscape to flatten the image (by recursively ungrouping until every path is under the top-level <svg> tag), you should have a bunch of paths that share a coordinate space. There are pathological cases like images that use CSS for positioning, but for most cases this will work.

Then you can use something like svgpathtools (https://github.com/mathandy/svgpathtools) in Python to loop over the paths and get the coordinates.

In case it's useful, I have an example svg to gcode converter here: https://github.com/paulgb/penkit/blob/master/penkit/polargra...

It is for driving a polargraph-style plotter, so it includes a coordinate transform that GP does not need to do.

Re:Show HN: Tool that turns your images into plotter-like li... by lights0123 on Thursday May 20, 2021 @08:25PM (#27229142)
(In the context of this post, which is just straight lines)
Re:Show HN: Tool that turns your images into plotter-like li... by javierbyte on Thursday May 20, 2021 @06:34PM (#27228284)
Yes, in this case the SVG is a list of coordinate pairs, should be fairly easy to extract.

https://github.com/javierbyte/pintr/blob/master/lib/svg.js#L...

* Update to add a link to the code that generates the SVG.

Re:Show HN: Tool that turns your images into plotter-like li... by roland35 on Thursday May 20, 2021 @07:46PM (#27228882)
Curves can be a bit more complicated, plus generating the tool lift and moves! I also need to factor in scaling the drawing as well, plus speeds.