An open API service indexing awesome lists of open source software.

https://github.com/boringdeveloper/p5js-to-svg


https://github.com/boringdeveloper/p5js-to-svg

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# p5js-to-svg

Use p5.js-svg library to convert the p5js element to svg. Add this in the `` tag of your index.html

```html

```

Create a button to save the svg file.
```html
Save SVG
```

In your sketch.js file, add this function.
```js
function downloadSvg() {
noLoop();

let svgElement = document.getElementsByTagName('svg')[0];
let svg = svgElement.outerHTML;
let file = new Blob([svg], { type: 'plain/text' });
let a = document.createElement("a"), url = URL.createObjectURL(file);

a.href = url;
a.download = 'exported.svg';
document.body.appendChild(a);
a.click();

setTimeout(function()
{
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
```

In the `createCanvas()` function, add the `SVG` parameter.
```js
createCanvas(1080, 1080, SVG);
```