This API is experimental
Its behavior may change in a future version of p5.js.
Downloads the sketch or a recorded shape as an SVG file. Supports two modes:
Deferred frame export: queues an automatic SVG export for a frame using p5.js lifecycle hooks (predraw and postdraw): saveSVG([filename])
Shape recording automatically starts at predraw and stops at postdraw, exporting the complete SVG immediately after the frame finishes drawing. When called in setup(), it captures the first frame of draw(). When called in draw() or event handlers (keyPressed, mousePressed), it schedules and captures on the next frame.
Direct shape export: immediately exports an existing p5.ShapeCollection: saveSVG(record, [filename])
Examples
Syntax
saveSVG([recordOrFilename], [filename])
Parameters
recordOrFilename
p5.ShapeCollection|String: a p5.ShapeCollection to export directly, or a filename string for deferred frame export.
filename
String: the downloaded file name. Only used when the first argument is a ShapeCollection.
Notice any errors or typos? Please let us know. Please feel free to edit src/shape/svg/svg_export.js and open a pull request!