import processing.pdf.*; //set box style. 1 is asymetrical, 2 is symetrical int boxStyle = 2; //set the resolution, in pixels per inch int resolution = 72; //set the box dimensions, in inches float boxWidthInches = .5; float boxDepthInches = .5; float boxHeightInches = .5; //calculate the box dimensions, in pixels int boxWidthPixels = round(boxWidthInches * resolution); int boxDepthPixels = round(boxDepthInches * resolution); int boxHeightPixels = round(boxHeightInches * resolution); int longside = max(boxWidthPixels,boxDepthPixels); int stageSize = (4*longside)+(2*boxHeightPixels) + 5; int stageCenter = stageSize/2; int flapCornerWidth = round(boxHeightPixels)+5; int flapCornerHeight = round(boxHeightPixels/3); int flapTopW = round(boxWidthPixels/2+5); int flapTopD = round(boxDepthPixels/2+5); int slitSpacing = round(flapCornerWidth/3); void setup() { size(stageSize, stageSize); noLoop(); beginRecord(PDF, "filename"+boxDepthInches+"x"+boxWidthInches+"x"+boxHeightInches+".pdf"); print(longside); } void draw() { //calculate starting point (bottom corner of the box). The box bottom should be centered on the screen. int startPointX = stageCenter - (boxWidthPixels/2); int startPointY = stageCenter - (boxDepthPixels/2); //name the corner coordinates for fun int cornerUpLeftX = startPointX; int cornerUpLeftY = startPointY; int cornerUpRightX = startPointX + boxWidthPixels; int cornerUpRightY = startPointY; int cornerDownRightX = startPointX + boxWidthPixels; int cornerDownRightY = startPointY + boxDepthPixels; int cornerDownLeftX = startPointX; int cornerDownLeftY = startPointY + boxDepthPixels; beginShape(); noFill(); //bottom top left vertex(startPointX, startPointY); vertex(startPointX-flapCornerWidth,startPointY-(boxHeightPixels)+flapCornerHeight); vertex(startPointX-5,startPointY-boxHeightPixels); vertex(startPointX-5,startPointY-boxHeightPixels-(boxDepthPixels/2)); //5 vertex(startPointX+boxWidthPixels+5, startPointY-boxHeightPixels-(boxDepthPixels/2)); vertex(startPointX+boxWidthPixels+5, startPointY-boxHeightPixels); //show this vertex on symetrical boxes, a if(boxStyle == 2){ vertex(cornerUpRightX+flapCornerWidth, cornerUpRightY - boxHeightPixels + flapCornerHeight); } vertex(startPointX+boxWidthPixels, startPointY); //show this vertex on asymetrical boxes, 8 if(boxStyle == 1){ vertex(startPointX+boxWidthPixels+boxHeightPixels-flapCornerHeight,startPointY-flapCornerWidth); } vertex(startPointX+boxWidthPixels+boxHeightPixels,startPointY-5); //10 vertex(startPointX+boxWidthPixels+boxHeightPixels+flapTopW,startPointY-5); endShape(); arc(startPointX+boxWidthPixels+boxHeightPixels+flapTopW, stageCenter,2*(stageCenter-(startPointY-5)), 2*(stageCenter-(startPointY-5)), TWO_PI-PI/2, PI/2); //slit for securing top line(startPointX+boxWidthPixels+boxHeightPixels+flapTopW, startPointY+(boxDepthPixels/2), startPointX+boxWidthPixels+boxHeightPixels+flapTopW, startPointY+boxDepthPixels+5); //start a new shape, gotta pick up the pen after that arc. beginShape(); //11 vertex(startPointX+boxWidthPixels+boxHeightPixels+flapTopW,startPointY+boxDepthPixels+5); vertex(startPointX+boxWidthPixels+boxHeightPixels,startPointY+boxDepthPixels+5); vertex(startPointX+boxWidthPixels,startPointY+boxDepthPixels); //start south flap, 14 vertex(startPointX+boxWidthPixels+flapCornerWidth,startPointY+boxDepthPixels+boxHeightPixels-flapCornerHeight); vertex(startPointX+boxWidthPixels+5,startPointY+boxDepthPixels+boxHeightPixels); //south top flap, 16 vertex(startPointX+boxWidthPixels+5,startPointY+boxDepthPixels+boxHeightPixels+flapTopD); vertex(startPointX-5,startPointY+boxDepthPixels+boxHeightPixels+flapTopD); vertex(startPointX-5,startPointY+boxDepthPixels+boxHeightPixels); if(boxStyle == 2){ vertex(cornerDownLeftX-flapCornerWidth,cornerDownLeftY+boxHeightPixels-flapCornerHeight); } vertex(startPointX,startPointY+boxDepthPixels); //west flap, 20 if(boxStyle == 1){ vertex(startPointX-boxHeightPixels+flapCornerHeight,startPointY+boxDepthPixels+flapCornerWidth); } //21 vertex(startPointX-boxHeightPixels,startPointY+boxDepthPixels+5); vertex(startPointX-boxHeightPixels-flapTopW,startPointY+boxDepthPixels+5); endShape(); arc(startPointX-boxHeightPixels-flapTopW,stageCenter,2*(stageCenter-(startPointY-5)),2*(stageCenter-(startPointY-5)),PI/2,TWO_PI-PI/2); line(startPointX-boxHeightPixels-flapTopW, startPointY-5, startPointX-boxHeightPixels-flapTopW, startPointY+(boxDepthPixels/2)); beginShape(); vertex(startPointX-boxHeightPixels-(boxWidthPixels/2)-10,startPointY-5); vertex(startPointX-boxHeightPixels,startPointY-5); vertex(startPointX,startPointY); endShape(); //draw slit on top side flap int slitHeightTop = (flapCornerHeight*(flapCornerWidth-slitSpacing))/flapCornerWidth; int slitHeightBottom = (slitSpacing*(boxHeightPixels-flapCornerHeight))/flapCornerWidth; if(boxStyle == 1) { line(cornerUpRightX - slitSpacing, cornerUpRightY - boxHeightPixels + flapCornerHeight - slitHeightTop, cornerUpRightX - slitSpacing, cornerUpRightY - slitHeightBottom); } if(boxStyle == 2){ line(cornerDownRightX + boxHeightPixels - flapCornerHeight + slitHeightTop, cornerUpRightY + slitSpacing, cornerDownRightX + slitHeightBottom, cornerUpRightY + slitSpacing); } line(cornerDownRightX + boxHeightPixels - flapCornerHeight + slitHeightTop, cornerDownRightY - slitSpacing, cornerDownRightX + slitHeightBottom, cornerDownRightY - slitSpacing); if(boxStyle == 1){ line(cornerDownLeftX + slitSpacing, cornerDownLeftY + boxHeightPixels - flapCornerHeight + slitHeightTop, cornerDownLeftX + slitSpacing, cornerDownLeftY + slitHeightBottom); } if(boxStyle == 2){ line(cornerDownLeftX - boxHeightPixels + flapCornerHeight - slitHeightTop, cornerDownLeftY - slitSpacing, cornerDownLeftX - slitHeightBottom, cornerDownLeftY - slitSpacing); } line(startPointX - boxHeightPixels + flapCornerHeight - slitHeightTop, startPointY + slitSpacing, startPointX - slitHeightBottom, startPointY + slitSpacing); endRecord(); }