CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
442 stars 28 forks source link

Remaining bits of Processing compatibility: arc(), square(), PShape/SVG #24

Closed golanlevin closed 4 years ago

golanlevin commented 4 years ago

Hi Lingdong, For thoroughness and compatibility with Processing, could you please add the following to PEmbroider:

This is more complex, but could you also add support for loading SVG files. Ideally this would use Processing's PShape code: https://processing.org/reference/PShape.html

Here is the code for a sample SVG to get you started, the rubber duck:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="107.59px" height="107.59px" viewBox="0 0 107.59 107.59" style="enable-background:new 0 0 107.59 107.59;"
     xml:space="preserve">
<g>
    <g>
        <path id="path5050" d="M96.264,34.699c-3.347-2.532-2.761,11.526-21.229,13.686c-6.061,0.707-11.467,0.123-16.271-1.017
            c-3.056-0.717-3.266-2.931-1.117-5.208c4.146-4.382,6.692-10.292,6.692-16.804c0-13.518-10.953-24.47-24.467-24.47
            c-9.802,0-18.25,5.758-22.158,14.075c-1.331,2.842-4.267,4.793-7.355,4.272C4.308,18.213,0,18.525,0,24.396
            c0,5.9,7.381,11.777,16.339,16.008c2.835,1.335,2.868,3.211,0.267,4.966C7.755,51.313,1.925,61.412,1.925,72.876
            c0,18.295,14.928,31.224,33.129,33.126c25.834,2.701,56.48-1.725,68.054-24.964C111.389,64.409,107.671,43.343,96.264,34.699"/>
    </g>
</g>
</svg>
Screen Shot 2020-06-14 at 4 34 59 PM

Although it's outside the official Processing spec, it would also be cool to add Alexandre B A Villares' "arcVertex":

LingDong- commented 4 years ago

Hi Golan,

I think how I would approach SVG is to load it with Processing, rasterize it on a canvas, and then use the image() or hatchRaster() routines to re-vectorize them. We'll be doing this anyways even if we obtain the original vector.

I think the SVG spec is pretty huge and not very practical to write a parser for. Processing has a baseline 2000 line parser that parses SVG into its internal format PShape, which I'll need to parse again to make use of. So I think the easiest (and most robust) approach will be to rasterize and trace.

arc square and rounded looks pretty simple to add!

LingDong- commented 4 years ago

Hi @golanlevin

All done! 5e1834239ca3d2184f032af6bba6cd5547af5170

PEmbroider_duck_arc_rounded_rect
golanlevin commented 4 years ago

Excellent!