- beginRecordSvg
- pauseRecordSvg
- endRecordSvg
- setSvgDocumentSize
- setSvgResolutionDPI
- setSvgResolutionDPCM
- setSvgInkscapeCompatibility
- setSvgDefaultStrokeWeight
- setSvgDefaultStrokeColor
- setSvgBackgroundColor
- setSvgIndent
- setSvgFlattenTransforms
- setSvgCoordinatePrecision
- setSvgTransformPrecision
- setSvgPointRadius
- setSvgGroupByStrokeColor
- setSvgMergeNamedGroups
- setSvgExportPolylinesAsPaths
- beginSvgGroup
- endSvgGroup
- getDefaultStrokeColor
- isRecordingSVG
Begins recording SVG output for a p5.js sketch. Initializes recording state, validates and sets the output filename, and overrides p5.js drawing functions to capture drawing commands for SVG export.
p5Instanceobject A reference to the current p5.js sketch (e.g.this).fnstring? Optional filename for the output SVG file. The explicit use ofnullwill prevent a file from being saved. Behavior:beginRecordSvg(this, "file.svg"); // saves to "file.svg"beginRecordSvg(this); // saves to "output.svg" (default)beginRecordSvg(this, null); // DOES NOT save any file!
Pauses or unpauses recording of SVG output for a p5.js sketch,
depending on whether the boolean bPause argument is true or false.
bPauseboolean
Ends recording of SVG output for a p5.js sketch. Calls the export function to generate the SVG output and restores the original p5.js functions. Returns the complete text of the SVG file as a string.
Sets the dimensions of the SVG document in pixels/dots.
Note that graphics are not scaled to fit this size; they may extend beyond the specified dimensions.
If this is not set, the system will default to the main canvas dimensions (i.e. from createCanvas()).
wnumber The SVG document width in pixels/dots. Must be a positive number.hnumber The SVG document height in pixels/dots. Must be a positive number.
Sets the resolution for the exported SVG file in dots per inch (DPI). This value is used to determine the scaling of units (pixels to physical dimensions) in the SVG output. The default is 96 dpi.
dpinumber The resolution in dots per inch. Must be a positive number.
Sets the resolution for the exported SVG file in dots per centimeter (DPCM).
This value is used to determine the scaling of units (pixels to physical dimensions) in the SVG output. The default resolution is approximately 37.79527559 dpcm (equivalent to 96 dpi).
dpcmnumber The resolution in dots per centimeter. Must be a positive number.
Enables or disables Inkscape-compatible layer attributes for SVG groups.
When enabled (which is the default), Inkscape headers will be added to the SVG, and SVG groups created with beginSvgGroup() will include
inkscape:groupmode="layer" and auto-numbered inkscape:label attributes. Disabling this mode produces 'vanilla' SVG files.
bEnabledboolean Enable or disable Inkscape layer compatibility. The default istrue: groups will include Inkscape layer attributes, and the SVG file will have Inkscape hints in its headers.
Sets the default stroke weight for SVG elements.
weinumber The stroke weight to set.
Sets the default stroke color for SVG elements.
colstring The stroke color to set, in valid CSS color format.
Sets an optional background color (as a CSS style) for the SVG. This is independent of the background() color of the p5 sketch.
This color does not interfere with plotter output and is purely for visualization. Note that this color may not be visible in all SVG viewers. If this function is not called, no background color style is specified in the SVG.
colstring The background color to set, in valid CSS color format.
Sets the type and amount of indentation used for formatting SVG output. The function allows for spaces, tabs, or no indentation.
itypestring The type of indentation to use. Valid values are 'SVG_INDENT_SPACES', 'SVG_INDENT_TABS', or 'SVG_INDENT_NONE'.inumnumber? Optional number of spaces or tabs to use for indentation. Must be a non-negative integer if provided. Defaults to 2 for spaces and 1 for tabs.
Set whether or not to use a stack to encode matrix transforms.
setSvgFlattenTransforms(true)-- larger SVG files, greater fidelity to originalsetSvgFlattenTransforms(false)-- smaller SVG files, potentially less fidelity
bboolean Whether or not to flatten geometric transforms
Sets the output precision for graphics coordinates in SVGs by adjusting the number of decimal digits used when formatting values. Default is 4 digits.
pnumber The desired number of decimal digits for coordinates. Must be a non-negative integer. If an invalid value is provided, a warning is issued.
Sets the output precision for matrix-transform values in SVGs by adjusting the number of decimal digits used when formatting rotations, translations, etc. Default is 6 digits.
pnumber The desired number of decimal digits for matrix values. Must be a non-negative integer. If an invalid value is provided, a warning is issued.
Sets the radius for "points" (which are rendered as tiny circles) in the SVG output. Default is 0.25 pixels.
radiusnumber The desired radius for points, specified as a positive number. If an invalid value (non-positive or non-number) is provided, a warning is issued.
Sets whether or not to group SVG elements by stroke color. When true, elements with the same stroke color, at the same level, will be grouped together.
bEnabledboolean Enable or disables grouping of elements by stroke color. The default isfalse.
Sets whether or not to merge user-defined SVG groups that have the same name.
Useful for grouping paths that might be computed at different times, but which are part of the same compositional design element, and should be plotted with the same drawing tool. The default is true, meaning that groups with the same name (which are at the same hierarchical level) will be merged. Note: There may be unexpected groupings if setSvgGroupByStrokeColor() is also set to true.
bEnabledboolean Whether or not groups with the same name should be merged.
Sets whether all polylines should be exported as <path> elements instead of the default case (which is <polyline> or <polygon>).
bbooleantrueto export polylines as<path>elements;falseto keep the default behavior.
Begins a new user-defined grouping of SVG elements.
Optionally associates a group name to the SVG group.
Be sure to call endSvgGroup() later or the SVG file will report errors.
gnamestring? Optional group name used as an ID for the SVG group.
Ends the current user-defined group of SVG elements.
Retrieves the default stroke color used for SVG rendering. Returns string, the default stroke color (in hex, RGB, or named CSS color format).
Retrieves whether or not SVG recording is active.
Returns boolean true if SVG recording is active, false otherwise.