import processing.pdf.*; int resolution = 72; //box dimensions in inches float boxSizeInches = 1.5; float boxThicknessInches = .13; float stemHeightInches = 3; float kerfInches = 0.008; //box dimensions in pixels int boxSize = round(boxSizeInches * resolution); int boxThickness = round(boxThicknessInches * resolution); int stemWidth = round(boxSize/3); int stemHeight = round(stemHeightInches * resolution); int kerf = round(kerfInches * resolution); int center = round((boxSize + 25)/2); void setup(){ size(boxSize*2+50+stemWidth,boxSize*3 + 50); noLoop(); beginRecord(PDF, "lampshade"+boxSizeInches+".pdf"); } void draw(){ int upLeftX = center - (boxSize/2); int upLeftY = 5; makeSide(upLeftX, upLeftY); makeSide(upLeftX+boxSize+10, upLeftY); //stem int stemUpLeftX = upLeftX+boxSize*2+20; beginShape(); vertex(stemUpLeftX, upLeftY); vertex(stemUpLeftX + stemWidth/2, upLeftY); vertex(stemUpLeftX + stemWidth/2, upLeftY + boxThickness); vertex(stemUpLeftX + stemWidth - boxThickness, upLeftY + boxThickness); vertex(stemUpLeftX + stemWidth - boxThickness, upLeftY + stemHeight/2); vertex(stemUpLeftX + stemWidth, upLeftY + stemHeight/2); vertex(stemUpLeftX + stemWidth, upLeftY + stemHeight); vertex(stemUpLeftX + stemWidth/2, upLeftY + stemHeight); vertex(stemUpLeftX + stemWidth/2, upLeftY + stemHeight - boxThickness); vertex(stemUpLeftX + boxThickness, upLeftY + stemHeight - boxThickness); vertex(stemUpLeftX + boxThickness, upLeftY + stemHeight/2); vertex(stemUpLeftX, upLeftY + stemHeight/2); endShape(CLOSE); upLeftY = upLeftY + boxSize + 10; makeSide(upLeftX, upLeftY); upLeftY = upLeftY + boxSize+10; makeTop(upLeftX,upLeftY); //holes for stem rect(center - stemWidth/2,upLeftY + boxSize/2 - stemWidth/2, stemWidth/2, boxThickness); rect(center + stemWidth/2 - boxThickness, upLeftY + boxSize/2 - stemWidth/2, boxThickness, stemWidth/2); rect(center,upLeftY + boxSize/2 + stemWidth/2 - boxThickness,stemWidth/2, boxThickness); rect(center - stemWidth/2,upLeftY + boxSize/2, boxThickness, stemWidth/2); ellipse(center, upLeftY+boxSize/2, 12,12); upLeftX = upLeftX + boxSize + 10; makeTop(upLeftX, upLeftY); endRecord(); } void makeSide(int upLeftX,int upLeftY){ beginShape(); noFill(); vertex(upLeftX, upLeftY); //top center vertex(upLeftX + boxSize/2+kerf, upLeftY); vertex(upLeftX + boxSize/2+kerf, upLeftY + boxThickness); //up right vertex(upLeftX + boxSize, upLeftY + boxThickness); vertex(upLeftX + boxSize, upLeftY + boxSize/2+kerf); vertex(upLeftX + boxSize - boxThickness, upLeftY + boxSize/2+kerf); vertex(upLeftX + boxSize - boxThickness, upLeftY + boxSize - boxThickness); vertex(upLeftX + boxSize, upLeftY + boxSize - boxThickness); //bottom right vertex(upLeftX + boxSize, upLeftY + boxSize); vertex(upLeftX + boxSize/2-kerf, upLeftY + boxSize); vertex(upLeftX + boxSize/2-kerf, upLeftY + boxSize - boxThickness); vertex(upLeftX, upLeftY + boxSize - boxThickness); vertex(upLeftX, upLeftY + boxSize/2-kerf); vertex(upLeftX + boxThickness, upLeftY + boxSize/2-kerf); vertex(upLeftX + boxThickness, upLeftY + boxThickness); vertex(upLeftX, upLeftY + boxThickness); endShape(CLOSE); } void makeTop(int upLeftX,int upLeftY){ beginShape(); noFill(); vertex(upLeftX + boxThickness, upLeftY); //top center vertex(upLeftX + boxSize/2, upLeftY); vertex(upLeftX + boxSize/2, upLeftY + boxThickness); //up right vertex(upLeftX + boxSize, upLeftY + boxThickness); vertex(upLeftX + boxSize, upLeftY + boxSize/2); vertex(upLeftX + boxSize - boxThickness, upLeftY + boxSize/2); //bottom right vertex(upLeftX + boxSize - boxThickness, upLeftY + boxSize); vertex(upLeftX + boxSize/2, upLeftY + boxSize); vertex(upLeftX + boxSize/2, upLeftY + boxSize - boxThickness); vertex(upLeftX, upLeftY + boxSize - boxThickness); vertex(upLeftX, upLeftY + boxSize/2); vertex(upLeftX + boxThickness, upLeftY + boxSize/2); endShape(CLOSE); }