Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
Press the "Regenerate" button to create a variation of the composition; press the "Export SVG" button to export an SVG.
CC Attribution NonCommercial ShareAlike
plotSvg_generative
Levin
xxxxxxxxxx
// https://github.com/golanlevin/p5.plotSvg (v.0.1.0)
// A Plotter-Oriented SVG Exporter for p5.js
// Golan Levin, November 2024
//
// This example demonstrates how to use the p5.plotSvg library to
// export SVG files from a simple "generative art" sketch in p5.js.
//
// Requires https://unpkg.com/p5.plotsvg@0.1.0/lib/p5.plotSvg.js or
// https://cdn.jsdelivr.net/npm/p5.plotsvg@latest/lib/p5.plotSvg.js
// Be sure to add one of these ^ in the SKETCH>LIBRARIES tab!
// This line of code disables the p5.js "Friendly Error System" (FES),
// to prevent some distracting warnings. Feel free to comment this out.
p5.disableFriendlyErrors = true;
let bDoExportSvg = false;
let myRandomSeed = 12345;
let regenerateButton;
let exportSvgButton;
//------------------------------------------------------------
function setup() {
createCanvas(576, 384); // 6"x4" at 96 dpi
regenerateButton = createButton('Regenerate');
regenerateButton.position(0, height);
regenerateButton.mousePressed(regenerate);
exportSvgButton = createButton('Export SVG');
exportSvgButton.position(100, height);
exportSvgButton.mousePressed(initiateSvgExport);
// Set important values for our SVG exporting:
setSvgResolutionDPI(96);
setSvgPointRadius(0.25);
setSvgCoordinatePrecision(4);
setSvgTransformPrecision(6);
setSvgIndent(SVG_INDENT_SPACES, 2);
setSvgDefaultStrokeColor('black');
setSvgDefaultStrokeWeight(1);
setSvgFlattenTransforms(false);
}
//------------------------------------------------------------
function regenerate(){
myRandomSeed = round(millis());
}
function initiateSvgExport(){
bDoExportSvg = true;
}
//------------------------------------------------------------
function draw(){
randomSeed(myRandomSeed);
background(245);
strokeWeight(1);
stroke(0);
noFill();
if (bDoExportSvg){
beginRecordSVG(this, "plotSvg_generative_" + myRandomSeed + ".svg");
}
// Draw 100 random lines.
let nLines = 100;
for (let i=0; i<nLines; i++){
let x1 = width * random(0.1, 0.9);
let y1 = height * random(0.1, 0.9);
let x2 = width * random(0.1, 0.9);
let y2 = height * random(0.1, 0.9);
line (x1,y1, x2,y2);
}
if (bDoExportSvg){
endRecordSVG();
bDoExportSvg = false;
}
}
See More Shortcuts
Please verify your email to comment
Verify Email