text: function setup(){img1=createImage(1200,800),d=pixelDensity(),loadPixels();var e=img1.height/620;if(cWidth=round(img1.width/e),cHeight=round(img1.height/e),cWidth>.9*window.innerWidth){e=img1.width/(.9*window.innerWidth);cWidth=round(img1.width/e),cHeight=round(img1.height/e)}myCanvas=createCanvas(cWidth,cHeight),origcWidth=cWidth,origcHeight=cHeight,canvasScale=1,triangleCanvasLayer=createGraphics(cWidth,cHeight),verticesCanvasLayer=createGraphics(cWidth,cHeight),generateHashSpace();for(var i=0;i<max_undo;i++)storedVertices.push([0,0]);recordVertices(),updateHashSpace(0,0,!0),updateHashSpace(cWidth,0,!0),updateHashSpace(0,cHeight,!0),updateHashSpace(cWidth,cHeight,!0);for(var a=0;a<cWidth/80;a++){var t=80*a+round(random(0,30)),s=80*a+round(random(0,30));inCanvas(t,cHeight)&&updateHashSpace(t,cHeight,!0),inCanvas(s,0)&&updateHashSpace(s,0,!0)}for(a=0;a<cHeight/80;a++){t=80*a+round(random(0,30)),s=80*a+round(random(0,30));inCanvas(cWidth,t)&&updateHashSpace(cWidth,t,!0),inCanvas(0,s)&&updateHashSpace(0,s,!0)}loadPixels(),frameRate(60),recordVertices(),verticesHashTableFlat=verticesHashTable.reduce(function(e,i){return e.concat(i)}),$("#gamedisplay").css("width",cWidth),$("#gamedisplay").css("margin-left",-cWidth/2),myCanvas.parent("gamedisplay"),angleMode(DEGREES),$("#downloadSVG").on("click",function(){!1===finishedColoring?alert("Please wait until the coloring is finished before enlargining the work and downloading it"):triangulations[triangulations.length-1].length>0?!0===display_mode_on?alert("At the moment, you can't download SVGs of the different display modes. Turn display mode off in settings to download SVG of the poly art"):downloadSVG(cWidth,cHeight):alert("Make some poly art first")}),console.log("Finished Setting Up!"),$("#loadingText").css("top","30%"),$("#loadingText").css("opacity","0"),$("#loadingScreen").css("opacity","0"),window.setTimeout(function(){$("#loadingScreen").css("z-index","-10"),$("#loadingText").html('Patience, we are making art <img src="images/loadingSymbol.gif" style="margin-left: 10px" width="32px" height="auto">')},1500),$("#brushSize")[0].value=brushSize,$("#brushDensity")[0].value=pointDensity+1,$("#defaultCanvas0").on("mouseenter",function(){active_canvas=!0}),$("#defaultCanvas0").on("mouseleave",function(){active_canvas=!1})}function colorIn(){image(img1,0,0,cWidth,cHeight),loadPixels(),sTime=millis();for(var e=0;e<triangulations[0].length-1;e+=3){var i=[0,0,0];i=averageColor(triangulatedVerticesFlat[triangulations[triangulations.length-1][e]][0],triangulatedVerticesFlat[triangulations[triangulations.length-1][e]][1],triangulatedVerticesFlat[triangulations[triangulations.length-1][e+1]][0],triangulatedVerticesFlat[triangulations[triangulations.length-1][e+1]][1],triangulatedVerticesFlat[triangulations[triangulations.length-1][e+2]][0],triangulatedVerticesFlat[triangulations[triangulations.length-1][e+2]][1],colorAccuracy),tColors.push(i[0],i[1],i[2])}finishedColoring=!0,fTime=millis(),console.log("Coloring took:"+((fTime-sTime)/1e3).toFixed(3)+" secs")}function draw(){if(background("#FFFFFF"),!0===displayImage&&image(img1,0,0,cWidth,cHeight),!0===flowerEffect)!0===flowering&&(delaunayDisplay(triangulations[0],triangleCanvasLayer,triangulatedVerticesFlat,!0,flower_step,flowering_speed),(flower_step+=flowering_speed)+1>triangulations[0].length/3&&(flowering=!1,fTime=millis(),console.log("Coloring took:"+((fTime-sTime)/1e3).toFixed(3)+" secs"),flower_step=0));else if(!1===finishedColoring){colorIn(),finishedColoring=!0;for(var e=0;e<triangulations.length;e++)delaunayDisplay(triangulations[e],triangleCanvasLayer)}if(stroke(2),colorOfSquares.length>0&&!0===squares){noStroke();for(var i=0;i<colorOfSquares.length;i++){var a=colorOfSquares[i];fill(a[0],a[1],a[2]),rect(a[3],a[4],20,20)}}if(fill(256,256,256),!0===displayTriangulation&&!0===finishedColoring&&(!0===flowerEffect&&!0===noColors?image(uncoloredTriangleCanvasLayer,0,0):image(triangleCanvasLayer,0,0)),fill(256,256,256),stroke(0,0,0),!0===displayPoints&&image(verticesCanvasLayer,0,0),!0===display_grid){strokeWeight(1),stroke(150);for(e=0;e<cWidth/snappingAccuracy;e++)line(e*snappingAccuracy,0,e*snappingAccuracy,cHeight);for(e=0;e<cHeight/snappingAccuracy;e++)line(0,e*snappingAccuracy,cWidth,e*snappingAccuracy)}$("#numberPoints").text(totalpoints+" points");var t=parseInt(triangulations[triangulations.length-1].length)/3;isNaN(t)?$("#numberTriangles").text("0 triangles"):$("#numberTriangles").text(t+" triangles"),!0===finishedColoring&&$("#lastTiming").text(((fTime-sTime)/1e3).toFixed(3)+" seconds");var s=oldX-mouseX,n=oldY-mouseY;if(accDist=sqrt(s*s+n*n),2===mode&&active_canvas)if(noFill(),stroke(200,200,200),ellipse(mouseX,mouseY,2*brushSize,2*brushSize),accDist>=critDist&&mouseIsPressed)if(displayPoints=!0,css_buttons.displayPoints(!0),mouseX>cWidth-1||mouseX<1||mouseY>cHeight-1||mouseY<1);else{accDist=0,critDist=random(15,20),oldX=mouseX,oldY=mouseY;var r=round(mouseX),o=round(mouseY);!0===snapping&&(r-=r%snappingAccuracy,o-=o%snappingAccuracy),unique_vertex(r,o)&&updateHashSpace(r,o,!0);for(var c=0;c<pointDensity;c++){var l=random(-brushSize,brushSize),d=sqrt(brushSize*brushSize-l*l),g=random(-d,d);if(mouseX+l>cWidth-1||mouseX+l<1||mouseY+g>cHeight-1||mouseY+g<1);else{r=round(mouseX+l),o=round(mouseY+g);1==snapping&&(r%snappingAccuracy<snappingAccuracy/2?r-=r%snappingAccuracy:r=r+snappingAccuracy-r%snappingAccuracy,o%snappingAccuracy<snappingAccuracy/2?o-=o%snappingAccuracy:o=o+snappingAccuracy-o%snappingAccuracy),unique_vertex(r,o)&&updateHashSpace(r,o,!0)}}}else mouseIsPressed||(critDist=0);if(3===mode&&!0===active_canvas&&(noFill(),stroke(200,200,200),ellipse(mouseX,mouseY,2*brushSize,2*brushSize),mouseIsPressed)){displayPoints=!0,css_buttons.displayPoints(!0);var h=mouseX,u=mouseY;erase_vertices(h,u,brushSize);for(var p=[],f=floor(round(h)/hashing_size)*hashing_size,m=floor(round(u)/hashing_size)*hashing_size,v=(findIndexFromHash(hashCoordinate(f,m)),p=[],-ceil(brushSize/hashing_size));v<=ceil(brushSize/hashing_size);v++)for(var y=-ceil(brushSize/hashing_size);y<=ceil(brushSize/hashing_size);y++){var _=f+hashing_size*v,H=m+hashing_size*y;inCanvas(_,H)&&p.push(findIndexFromHash(hashCoordinate(_,H)))}for(e=0;e<p.length;e++){var S=verticesHashTable[p[e]];for(y=0;y<S.length;y++)verticesCanvasLayer.ellipse(S[y][0],S[y][1],5,5)}}!0===filteringView&&(pixels=filteredPixels,updatePixels())}function generate_normal_poly(e){noLoop(),$("#loadingScreen").css("z-index","10"),$("#loadingScreen").css("opacity","1"),$("#loadingText").css("top","50%"),$("#loadingText").css("opacity","1"),filteredPixels.length>0&&1==completedFilters?copyTo(filteredPixels,pixels):(image(img1,0,0,cWidth,cHeight),filter(GRAY),loadPixels()),!0===flowerEffect&&(flower_step=0,flowering=!0);var i=new Worker("scripts/webworkerArtGen.min.js"),a=e[5];if(0==completedFilters){var t=millis();detected_edge_vertices=[],i.postMessage([[e[0],e[1]],pixels,e[2],e[3],e[4]]),i.onmessage=function(e){var i=e.data,s=millis();generateHashSpace();for(var n=0;n<i[0].length;n++)detected_edge_vertices.push([i[0][n][0],i[0][n][1],i[0][n][2]]);copyTo(i[1],pixels);for(var r=0;r<pixels.length;r++)filteredPixels.push(pixels[r]);normal_poly_update_points(a,4,.2),console.log("Webworker took "+(s-t)/1e3+"s","Area: "+cWidth*cHeight)}}else normal_poly_update_points(a,4,.2)}function normal_poly_update_points(e,i,a){generateHashSpace();for(var t=0;t<detected_edge_vertices.length;t++)if(detected_edge_vertices[t][2]>=colorThreshold){var s=detected_edge_vertices[t][0],n=detected_edge_vertices[t][1];updateHashSpace(s,n,!0,detected_edge_vertices[t][2])}splitSquare(e*i),generateRandomSquares(e*i,a),reduce_point_density_by_brightness(2*e),reduce_point_density(e,!1),updateHashSpace(0,0,!0),updateHashSpace(cWidth,0,!0),updateHashSpace(0,cHeight,!0),updateHashSpace(cWidth,cHeight,!0);for(t=0;t<cWidth/(3*e);t++){var r=t*e*3+Math.round(random(0,e)),o=t*e*3+Math.round(random(0,e));inCanvas(r,cHeight)&&updateHashSpace(r,cHeight,!0),inCanvas(o,0)&&updateHashSpace(o,0,!0)}for(t=0;t<cHeight/(3*e);t++){r=t*e*3+Math.round(random(0,e)),o=t*e*3+Math.round(random(0,e));inCanvas(cWidth,r)&&updateHashSpace(cWidth,r,!0),inCanvas(0,o)&&updateHashSpace(0,o,!0)}draw_all_points(verticesCanvasLayer,verticesHashTable),triangulate_and_display(),completedFilters=!0,$("#loadingScreen").css("opacity","0"),$("#loadingText").css("opacity","0"),$("#loadingText").css("top","30%"),window.setTimeout(function(){$("#loadingScreen").css("z-index","-10")},1500),loop(),recordVertices()}function reduce_point_density_by_brightness(e,i){for(var a=255;a>=4;a--)for(var t=0;t<verticesHashTable.length;t++)for(var s=0;s<verticesHashTable[t].length;s++)if(3==verticesHashTable[t][s].length&&verticesHashTable[t][s][2]==a){var n=verticesHashTable[t][s][0],r=verticesHashTable[t][s][1],o=verticesHashTable[t][s][2];erase_vertices(n,r,e),updateHashSpace(n,r,!0,o)}}function reduce_point_density(e,i){for(var a=0;a<verticesHashTable.length;a++)for(var t=0;t<verticesHashTable[a].length;t++){var s=verticesHashTable[a][t][0],n=verticesHashTable[a][t][1];erase_vertices(s,n,e),updateHashSpace(s,n,!0,void 0)}}var myCanvas,img1,d,triangleCanvasLayer,verticesCanvasLayer,uncoloredTriangleCanvasLayer,triangulations=[0],tColors=[],mode=1,colorOfSquares=[],displayTriangulation=!0,displayPoints=!0,displayImage=!0,display_grid=!1,noColors=!1,flowing=!0,brushSize=100,finishedColoring=!0,quickColor=!1,sTime=0,fTime=0,squares=!1,colorAccuracy=1,verticesHashTable=[],verticesHashTableFlat=[],totalpoints=0,triangulatedVerticesFlat=[],pointDensity=4,flowerEffect=!1,filteringView=!1,displayEdgePoints=!1,snapping=!1,snappingAccuracy=20,displayMode=0,artstyle=0,storedVertices=[],max_undo=50,cWidth=400,cHeight=400,active_canvas=!1,accDist=0,oldX=0,oldY=0,critDist=10,flowering=!1,flower_step=0,flowering_speed=1,filteredPixels=[],detected_edge_vertices=[],jitter_deviation=20,max_jitter_count=3,jitter_prob=.85;