varc=preview_tmp.toDataURL();doodleImageCapture=newImage,doodleImageCapture.onload=function(){previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(vara=0,b=0,c=0;numLayers>c;c++){vard=scaleFunction(c/maxNumLayers);previewCtx.globalAlpha=0==c||c==Math.floor(numLayers/2)||c==numLayers-1?1:globalAlpha,previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+a),previewCtx.scale(d,scaleY*d),previewCtx.rotate(b),previewCtx.translate(-layerCX,-layerCY),previewCtx.drawImage(doodleImageCapture,0,0),a-=yStep,b+=rStep,previewCtx.restore()}},doodleImageCapture.src=c,previewCtx.globalAlpha=globalAlpha}}functionredrawRenderedPreview(a){void0==a&&(a=!1),console.log("f:redrawRenderedPreview()"),previewCtx.clearRect(0,0,preview.width,preview.height),previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(varb=0,c=0,d=0;numLayers>d;d++){vare=scaleFunction(d/maxNumLayers);previewCtx.globalAlpha=0==d||d==Math.floor(numLayers/2)||d==numLayers-1?1:globalAlpha,a&&0!=d%2&&0!=d&&d!=Math.floor(numLayers/2)&&d!=numLayers-1?(b-=yStep,c+=rStep):(previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+b),previewCtx.scale(e,scaleY*e),previewCtx.rotate(c),previewCtx.translate(-layerCX,-layerCY),previewCtx.drawImage(doodleImageCapture,0,0),b-=yStep,c+=rStep,previewCtx.restore())}}functioncenteredAndScaledDoodlePoint(a){varb={x:0,y:0};returnb.x=(a[0]-(doodleBounds[2]-doodleBounds[0])/2)*globalScale*doodleTransform[2],b.y=(a[1]-(doodleBounds[3]-doodleBounds[1])/2)*globalScale*doodleTransform[3],b}functionupdatePreview(a,b,c){if(void0==c&&(c=!1),c=!1,!(_points.length<2)){if(-1==updatePrevX||-1==updatePrevY)returnupdatePrevX=a,updatePrevY=b,void0;vard=0,e=0;previewCtx.lineWidth=strokeWidth,previewCtx.strokeStyle="#f00";for(varf=0;numLayers>f;f++)if(previewCtx.globalAlpha=0==f||f==Math.floor(numLayers/2)||f==numLayers-1?1:globalAlpha,c&&0!=f%debug_redrawSimplification&&0!=f&&f!=Math.floor(numLayers/2)&&f!=numLayers-1)d-=yStep,e+=rStep;else{previewCtx.save(),previewCtx.translate(layerCX,layerOffsetY+d),previewCtx.scale(viewerScale,scaleY*viewerScale),previewCtx.rotate(e),previewCtx.translate(-doodleTransform[0]*globalScale*doodleTransform[2],-doodleTransform[1]*globalScale*doodleTransform[3]),previewCtx.beginPath();varg=centeredAndScaledDoodlePoint([updatePrevX,updatePrevY]);previewCtx.moveTo(g.x,g.y);varh=centeredAndScaledDoodlePoint([a,b]);previewCtx.lineTo(h.x,h.y),previewCtx.stroke(),d-=yStep,e+=rStep,previewCtx.restore()}previewCtx.globalAlpha=globalAlpha,updatePrevX=a,updatePrevY=b}}functiongenerate_gcode(){console.log("f:generategcode()");vara=110,b=110;gcode=[],console.log("settings: ",settings);varc=settings["printer.speed"],d=c,e=.5*c,f=settings["printer.travelSpeed"],g=settings["printer.filamentThickness"],h=settings["printer.wallThickness"],i=settings["printer.screenToMillimeterScale"],j=settings["printer.layerHeight"],k=settings["printer.maxObjectHeight"],l=settings["printer.temperature"],m=settings["printer.bed.temperature"],n=settings["printer.useSubLayers"],o=settings["printer.enableTraveling"],p=settings["printer.retraction.enabled"],q=settings["printer.retraction.speed"],r=settings["printer.retraction.minDistance"],s=settings["printer.retraction.amount"],t=settings["printer.heatup.temperature"],u=settings["printer.heatup.bed.temperature"],v=settings["printer.startgcode"];v=subsituteVariables(v,l,m,t,u),v=v.split("\n");varw=settings["printer.endgcode"];w=subsituteVariables(w,l,m,t,u),w=w.split("\n");varx=k/j;objectHeight=Math.round(numLayers/maxNumLayers*k);vary=rStep*maxNumLayers/x;y=-y;varz=JSON.parse(JSON.stringify(_points));gcode=gcode.concat(v);varx=k/j,A=0,B=newPoint;B.set(0,0);varC={x:doodleBounds[0]+(doodleBounds[2]-doodleBounds[0])/2,y:doodleBounds[1]+(doodleBounds[3]-doodleBounds[1])/2};if(console.log("f:generategcode() >> layers: "+x),1/0!=x){varD=z.length*x*(objectHeight/k);if(D>MAX_POINTS_TO_PRINT)returnalert("Sorry, your doodle to to complex and / or to high"),console.log("WARNING:tomanypointstoconverttog