xxxxxxxxxx
111
/* export SVG
DDF 2019
need to have p5.svg.js in project and in index.html
see -https://github.com/zenozeng/p5.js-svg
this will save an SVG file in your download folder
*/
var origXpoints = [];
var origYpoints = [];
var npointsInit = 360;
function makeCircle( oldx=0,oldy=0) {
var radius = random() * width / 10;
var randomStartAngle = random() * PI;
var randomEndAngle = random() * -TWO_PI;
var xpoints = [];
var ypoints = [];
for (var i = 0; i < npointsInit; i++) {
var t = map(i, 0, npointsInit, randomStartAngle, -randomEndAngle);
var px = radius * cos(t)
var py = radius * sin(t)
xpoints[i] = px;
ypoints[i] = py;
print('yo')
if(outOfBounds(px, py)){
break;
}
}
shiftx = oldx -xpoints[0];
shifty = oldy -ypoints[0];
for (var j = 0; j < npointsInit; j++) {
xpoints[j] = xpoints[j] + shiftx;
ypoints[j] = ypoints[j] + shifty;
}
return [xpoints, ypoints]
}
function outOfBounds(x,y){
if(-width / 2 <= x && x <= width && -height / 2 <=y && y <=height){
return false;
}
return true
}
function drawCircle(oldx=0, oldy=0){
[xpoints, ypoints] = makeCircle(oldx, oldy);
tx = xpoints[0]
ty = ypoints[0]
for (var j = 0; j < xpoints.length; j++) {
var x = xpoints[j];
var y = ypoints[j];
line(tx, ty, x, y);
tx = x;
ty = y;
}
oldx = xpoints[xpoints.length -2];
oldy = ypoints[ypoints.length -2];
return [oldx, oldy]
}
function setup() {
createCanvas(400, 400, SVG);
strokeWeight(2); // do 0.1 for laser
stroke(0, 0, 0); // red is good for laser
strokeWeight(0.4)
noFill(); // better not to have a fill for laser
}
function draw() {
translate(width / 2, height / 2);
[oldx, oldy] = drawCircle();
threshold = 17;
while(threshold > 0){
[oldx, oldy] = drawCircle(oldx, oldy);
threshold -=1
}
// save("mySVG.svg"); // give file name
// print("saved svg");
noLoop(); // we just want to export once
}