-
Notifications
You must be signed in to change notification settings - Fork 120
SVG output #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Simple support would be great, but SVG reading writing can be extremely complex -- some python libraries that exist and might help with this undertaking are svgwrite, drawsvg, cairo svg. In terms of what exists currently (read) -- I believe that it is here: PShape in Java mode is a bit of a crazy mess -- partly because its internal representation and how its methods work differs based on whether you create one from SVG, or from as a new primitive, or by drawing vertices. It would be nice to not repeat those mistakes while building out: |
Yes. Handling svgs is surprising complex. Personally, the ultimate reason I’d like this feature is so I can send the output file to my pen plotter. ... any idea if there is any current interchange method that could do this? |
I was just taking a peek at the svg parser, and had a question: Once the parser determines that a path may be a particular shape (for instance, it parses an SVG and finds a 'rectangle'), and it converts that to a PShape, does the PShape know that it is a rectangle? Or no? Seems like that would determine where the SVG functions live. At the PShape level, or it's derived shape classes. Like the reader does, the writer would need to know what the 'shape' each PShape is. If that logic could be bidirectional (SVG reader and writer), then it could be a step in the right direction. |
@marcrleonard the SVG parser does not store the meta information of the shape (rect, circle, etc)
I believe Processing has a good rendering engine for exporting in PDFs and SVGs: https://processing.org/reference/libraries/svg/index.html |
It does, but I don't want to use processing... I want to use python ;-) I would like to start hacking on SVG output for p5py. To mirror p5.js, that would ultimately be part of the |
Sorry to spam this thread, but I've got some more questions: |
The p5.js
Yes, the vertex data is converted into
Yes, depending on the shape, its relevant shape attributes are added to the draw_queue (https://github.com/p5py/p5/blob/master/p5/sketch/renderer2d.py#L282). This includes:
Yes |
Here is how an svg is saved in P5.js: https://editor.p5js.org/dannyrozin/sketches/r1djoVow7 ... In classic P5 form, it's a very odd API. You have to first define the canvas to be an SVG canvas, then it is saved. Is this to be mirrored here? Looking for any implementation details that my be helpful. Is there some sort of hook or plugin architecture I could utilize? That way, it doesn't have to get baked into the core architecture (if the contributors don't want it). |
If you look at the Svg output from the p5js sketch above, you’ll see that each transform is applied to each element recursively (to reflect the loop). It appears that the p5.renderer does not track transforms in a similar way. It appears all transforms are flattened before going to the GPU for final render (which is perfectly logical). Is there a place where transforms are stored individually, so they can be applied to all the ‘underlying’ elements? Or does each transform get applied directly to the vertices, and left there? |
Here is a crazy simplistic version I've started with. It doesn't support all the fills/strokes/etc... But it seems to work properly for simple lines and circles (though, the circles use 'triangles' ... so that is probably not ideal).
(as per a comment in there) why is |
No, when a function for a shape is called, its vertices are transformed and stored in the queue for rendering: https://github.com/p5py/p5/blob/master/p5/sketch/renderer2d.py#L221 |
The |
Ok thanks. This will be a fundamental difference between how the SVG is created (versus p5.js). But honestly, it's better this way. Way less recursive mess :-) |
I think this is a really good implementation. I was able to use it with minor changes. |
Great. I've also made some tweaks since. If you all want to continue with this code, is there a place I can start contributing/committing? |
This can be added in the The |
Adding SVG output support would be great for people using pen-plotters! Thanks for working on this!! |
I second that! Thanks for working on this! And SVG output would also be great for generative art archiving, and infinitely scalable images! |
Maybe one could have a look at what Ricardo Lafonte and Stuart Axon are doing with pycairo & pango at http://github.com/shoebot/shoebot (I suppose Skia anf Flat could be ways to solve this too) |
Are there any plans for SVG output? This would be a fantastic feature, as I know it's used a lot in processing and p5? Would this be attached to the PShape class?
The text was updated successfully, but these errors were encountered: