feat(svg): add native p5.svg experimental feature module and contributor docs - #9123
feat(svg): add native p5.svg experimental feature module and contributor docs#9123VANSH3104 wants to merge 7 commits into
Conversation
…gister in src/app.js
|
@davepagurek I’ve added the code for this. Let me know what you think or if anything needs to be changed! |
ksen0
left a comment
There was a problem hiding this comment.
Very exciting to see this! Added some high-level documentation comments. Non blocking
|
|
||
| # p5.svg Overview | ||
|
|
||
| `p5.svg` is an experimental native vector graphics system provided in p5.js starting from version 2. It aims to bring resolution-independent vector rendering, SVG file importing, and SVG XML exporting directly into p5.js without requiring external third-party addons. It allows users to record 2D drawing operations using familiar p5 APIs (`rect`, `circle`, `path`, `fill`, `stroke`, `translate`, `rotate`, etc.) and convert them into scalable vector structures. |
|
|
||
| `p5.svg` addresses several key goals: | ||
|
|
||
| - **Resolution-Independent Vector Output**: Traditional canvas rendering in p5.js is raster (pixel) based. `p5.svg` enables artists, designers, and educators to generate scalable vector graphics suitable for high-DPI displays, print, pen plotters, CNC routers, laser cutters, and embroidery machines. |
There was a problem hiding this comment.
"p5.svg enables artists, designers, and educators to generate scalable vector graphics suitable for high-DPI displays, print, pen plotters, CNC routers, laser cutters, and embroidery machines." Feels like it should be in the opening paragraph?
| `p5.svg` addresses several key goals: | ||
|
|
||
| - **Resolution-Independent Vector Output**: Traditional canvas rendering in p5.js is raster (pixel) based. `p5.svg` enables artists, designers, and educators to generate scalable vector graphics suitable for high-DPI displays, print, pen plotters, CNC routers, laser cutters, and embroidery machines. | ||
| - **Familiar p5 Drawing Workflow**: Rather than introducing a complex vector editing paradigm, `p5.svg` hooks directly into the existing 2D drawing pipeline. You can record shapes using standard p5 drawing functions inside `createShape()` or `buildShape()`. |
There was a problem hiding this comment.
I think this phrasing should be simplified, eg not "Rather than introducing a complex vector editing paradigm, p5.svg hooks directly into the existing 2D drawing pipeline. You can record shapes using standard p5 drawing functions inside createShape() or buildShape()." but, "to create SVG output, the only thing you need to do differently is use crateshape and build shape. Inside these functions, use standard drawing API (rect, circle, path, fill, stroke, translate, rotate, etc.) as you usually would
|
|
||
| # p5.svg Overview | ||
|
|
||
| `p5.svg` is an experimental native vector graphics system provided in p5.js starting from version 2. It aims to bring resolution-independent vector rendering, SVG file importing, and SVG XML exporting directly into p5.js without requiring external third-party addons. It allows users to record 2D drawing operations using familiar p5 APIs (`rect`, `circle`, `path`, `fill`, `stroke`, `translate`, `rotate`, etc.) and convert them into scalable vector structures. |
There was a problem hiding this comment.
I think this paragraph should use very simple terms, nothing significantly technical (ie not "resolution-independent")
|
|
||
| The main ways you can help develop `p5.svg` are: | ||
|
|
||
| - **API Ergonomics & Shape API**: Test vector shape recording and rendering functions like `createSVG()`, `loadSVG()`, `buildShape()`, `createShape()`, `shape()`, `getSVG()`, and `saveSVG()`. Share feedback on `shape()` playback, coordinate bounds, positioning, scaling options, and alignment modes (`CORNER`, `CENTER`, `VIEWBOX`). |
There was a problem hiding this comment.
This section could be just "Shape API". I do not recommend the phrase "ergonomics," because in general API ergonomics does not imply a focus on learning and beginners as a user group, which is a specific focus in p5.js (part of access statement that relates to this feature)
In this case, in the whole feedback section, maybe it is useful top provide a bit more context on what the priorities are: maintaining familiarity with rest of p5.js; creating non-OOP, top-level, readable function calls to allow smooth svg recording / loading. The question is not ergonomics generally but: "how does this feel as a beginner?" or "if you teach with p5.js, do you see API choices that would be tricky for students?"
That's still quite broad, but for example, feedback like "I think this should be more compact / more OOP" would not really be relevant/applicable.
Just a general feedback, please feel free to implement as much as it makes sense
| import strands from './strands/p5.strands'; | ||
| p5.registerAddon(strands); | ||
| import svg from './shape/svg/p5.svg'; | ||
| p5.registerAddon(svg); |
Resolves #4630
Changes:
Native SVG Module (
src/shape/svg/): Added core SVG export, import, and shape recording capabilities:svg_recorder.js:ShapeRecorderAST node graph (ScopeNode,ShapeNode,BackgroundNode,ClearNode,ImageNode) andTransformStack.svg_export.js:SVGExportAddon,SVGVisitorXML DOM renderer, and public APIs (createShape(),buildShape(),getSVG(),shape(),saveSVG()).svg_import.js:SVGImportAddon, path command parser (M,L,C,S,Q,A,Z), element converters, and public APIs (createSVG(),async loadSVG()).p5.svg.js: SVG module entry point combining export and import addons.Core Addon Registration (
src/app.js): Registeredsvgaddon viap5.registerAddon(svg), bundling SVG capabilities directly into mainlib/p5.js.Experimental Warning System (
src/core/experimental.js): Added'p5.svg'message toexperimentalMessagesand wrapped public SVG prototype methods withmarkExperimental('p5.svg', p5)warning decorators.Contributor Documentation (
contributor_docs/p5.svg.md): Created contributor guide covering project goals, API ergonomics, technical architecture, and community guidelines.PR Checklist
npm run lintpasses