-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.min.js
1 lines (1 loc) · 1.76 KB
/
sketch.min.js
1
function setup(){createCanvas(1111,1111).parent("canvasContainer"),background(255),noLoop(),select("#drawButton").mousePressed(drawNewLines),select("#autoButton").mousePressed(toggleAutoplay),select("#clearButton").mousePressed(clearDrawing),select("#exportSVGButton").mousePressed(exportSVG),select("#exportPNGButton").mousePressed(exportPNG)}let lines=[],autoplay=!1;function draw(){autoplay&&drawNewLines()}function drawNewLines(){for(let t=0;t<1111;t++){let t={x1:random(width),y1:random(height),x2:random(-50,50),y2:random(-50,50),cx1:random(-10,10),cy1:random(-10,10),cx2:random(-10,10),cy2:random(-10,10),strokeWeight:random(.5,1.5)};lines.push(t),drawLine(t)}}function drawLineWithGraphics(t,e){e.stroke(0),e.strokeWeight(t.strokeWeight);let a=t.x1+t.x2,n=t.y1+t.y2,o=t.x1+t.cx1,r=t.y1+t.cy1,s=a+t.cx2,i=n+t.cy2;e.bezier(t.x1,t.y1,o,r,s,i,a,n),e.line(t.x1,t.y1,a,n)}function drawLine(t){drawLineWithGraphics(t,this)}function drawLineSVG(t,e){drawLineWithGraphics(t,e)}function toggleAutoplay(){autoplay=!autoplay,autoplay?(frameRate(3),select("#autoButton").html("Stop Growing"),loop()):(frameRate(60),select("#autoButton").html("Watch Grow"),noLoop())}function clearDrawing(){background(255),lines=[]}function getFormattedTimestamp(){const t=new Date,e=t.getFullYear(),a=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),o=t.getHours();return`${e}-${a}-${n} at ${o%12||12}.${String(t.getMinutes()).padStart(2,"0")}.${String(t.getSeconds()).padStart(2,"0")} ${o>=12?"pm":"am"}`}function exportSVG(){const t=`Watch Grass by Benbodhi - ${getFormattedTimestamp()}.svg`;let e=createGraphics(1111,1111,SVG);lines.forEach((t=>drawLineSVG(t,e))),save(e,t),e.remove()}function exportPNG(){const t=`Watch Grass by Benbodhi - ${getFormattedTimestamp()}.png`;saveCanvas(t,"png")}