diff --git a/CreasePatternScripts/SquareTwist/SquareTwist.pde b/CreasePatternScripts/SquareTwist/SquareTwist.pde new file mode 100755 index 0000000000000000000000000000000000000000..12acc9e1a89879f5d5a1cd3bce0d76b1323249af --- /dev/null +++ b/CreasePatternScripts/SquareTwist/SquareTwist.pde @@ -0,0 +1,166 @@ +import processing.pdf.*; + +boolean mountValleyColors = true; +boolean dashedCreaseLines = true; + +float angle = PI/3;// PI/2 > angle > 0 +float edgeLength = 72;//1in and 72dpi +float diagLength = 2*edgeLength/sqrt(2); + +void setup() { + size(400, 400); + + //tesselation + beginRecord(PDF, "squaretwisttesselation.pdf"); + background(255); + + makeUnitCell(200,200); + + endRecord(); + + //single twist + beginRecord(PDF, "squaretwist.pdf"); + background(255); + makeSingleUnitCell(width/2,height/2); + endRecord(); + + //many single twists + size(700, 700); + beginRecord(PDF, "squaretwistManyAngles.pdf"); + + background(255); + for (int i=0;i<3;i++){ + for (int j=0;j<3;j++){ + float index = i*3+j; + angle = map(index, 0, 8, PI/6, 2*PI/6); + makeSingleUnitCell(j*width/3+width/6,i*height/3+height/6); + } + } + + endRecord(); + +// // Exit the program + println("Finished."); + exit(); +} + +void makeSingleUnitCell(float x, float y){ + makeUnitCell(x, y, true, true, true, true, true); +} + +void makeUnitCell(float x, float y){ + makeUnitCell(x, y, false, false, false, false, false); +} + +void makeUnitCell(float x, float y, boolean allBounds, +boolean leftBounds, boolean topBounds, boolean bottomBounds, boolean rightBounds){ + pushMatrix(); + translate(x, y); + rotate(-angle/2); + + setMountainColor(); + //top + float square1X = diagLength/2*sin(angle-PI/4); + float square1Y = -diagLength/2*cos(angle-PI/4); + + //right + float square2X = diagLength/2*sin(angle+PI/4); + float square2Y = -diagLength/2*cos(angle+PI/4); + + drawCrease(square1X, square1Y, square1X, square1Y-edgeLength); + drawCrease(-square1X, -square1Y, -square1X, -square1Y+edgeLength); + + drawCrease(square2X, square2Y, square2X+edgeLength, square2Y); + drawCrease(-square2X, -square2Y, -square2X-edgeLength, -square2Y); + + //inner square + drawCrease(square1X, square1Y, square2X, square2Y); + drawCrease(square1X, square1Y, -square2X, -square2Y); + drawCrease(-square1X, -square1Y, square2X, square2Y); + drawCrease(-square1X, -square1Y, -square2X, -square2Y); + + //bounds + if (allBounds) setCutColor(); + + if (leftBounds){ + //left + line(square1X-edgeLength, square1Y-edgeLength, square1X-edgeLength, square1Y); + line(square1X-edgeLength, square1Y, -square2X-edgeLength, -square2Y); + line(-square2X-edgeLength, -square2Y, -square2X-edgeLength, -square2Y+edgeLength); + } + + if (topBounds){ + //top + line(square1X, square1Y-edgeLength, square1X-edgeLength, square1Y-edgeLength); + line(square1X, square1Y-edgeLength, square2X, square2Y-edgeLength); + line(square2X, square2Y-edgeLength, square2X+edgeLength, square2Y-edgeLength); + } + + if (rightBounds){ + //right + line(square2X+edgeLength, square2Y-edgeLength, square2X+edgeLength, square2Y); + line(square2X+edgeLength, square2Y, -square1X+edgeLength, -square1Y); + line(-square1X+edgeLength, -square1Y, -square1X+edgeLength, -square1Y+edgeLength); + } + + if (bottomBounds){ + //bottom + line(-square1X+edgeLength, -square1Y+edgeLength, -square1X, -square1Y+edgeLength); + line(-square1X, -square1Y+edgeLength, -square2X, -square2Y+edgeLength); + line(-square2X, -square2Y+edgeLength, -square2X-edgeLength, -square2Y+edgeLength); + } + + setValleyColor(); + drawCrease(square1X, square1Y, square1X-edgeLength, square1Y); + drawCrease(-square1X, -square1Y, -square1X+edgeLength, -square1Y); + + drawCrease(square2X, square2Y, square2X, square2Y-edgeLength); + drawCrease(-square2X, -square2Y, -square2X, -square2Y+edgeLength); + + popMatrix(); +} + +void setMountainColor(){ + if (mountValleyColors){ + stroke(0,0,255);//blue + } else { + setCreaseColor(); + } +} + +void setValleyColor(){ + if (mountValleyColors){ + stroke(255,0,0);//red + } else { + setCreaseColor(); + } +} + +void setCutColor(){ + stroke(0);//black +} + +void setCreaseColor(){ + stroke(255,0,0);//red +} + +void drawCrease(float x1, float y1, float x2, float y2){ + if (dashedCreaseLines){ + dashedLine(x1, y1, x2, y2, 6, 6); + } else { + line(x1, y1, x2, y2); + } +} + +void dashedLine(float x1, float y1, float x2, float y2, float dashLength, float spaceLength){ + pushMatrix(); + translate(x1, y1); + rotate(atan2(y2-y1, x2-x1)); + float lineLength = sqrt((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1)); + float partialDash = lineLength/(dashLength+spaceLength) - floor(lineLength/(dashLength+spaceLength)); + for (float i=(partialDash+spaceLength)/2;i<lineLength;i+=dashLength+spaceLength){ + line(i, 0, i+dashLength, 0); + } + popMatrix(); +} + diff --git a/CreasePatternScripts/TriTesselation/TriTesselation.pde b/CreasePatternScripts/TriTesselation/TriTesselation.pde new file mode 100755 index 0000000000000000000000000000000000000000..bd6fdce0373f027ffa81efe6a9d6d6b8e79588a3 --- /dev/null +++ b/CreasePatternScripts/TriTesselation/TriTesselation.pde @@ -0,0 +1,74 @@ +import processing.pdf.*; + +float triangleHeight = 40;//40px/72dpi = ~0.55in tall +boolean dashedCreaseLines = true; + +void setup() { + + //20in*72dpi= 1440px + size(1440, 1440, PDF, "tritesselation.pdf"); + background(255); + + //horizontal lines + for (float i=triangleHeight;i<height;i+=triangleHeight){ + drawCrease(0, i, width, i); + } + + // \\\\\\ lines + for (float i=-height/sqrt(3);i<width;i+=2*triangleHeight/sqrt(3)){ + + float xPos = i+height/sqrt(3); + if (xPos>width){ + float xDiff = xPos-width; + drawCrease(i, 0, width, height-xDiff*sqrt(3)); + } else if (i<0){ + float xDiff = -i; + drawCrease(0, xDiff*sqrt(3), i+height/sqrt(3), height); + } else { + drawCrease(i, 0, i+height/sqrt(3), height); + } + } + + // //////// lines + for (float i=0;i<width+height/sqrt(3);i+=2*triangleHeight/sqrt(3)){ + + float xPos = i-height/sqrt(3); + if (i>width){ + float xDiff = i-width; + drawCrease(width, xDiff*sqrt(3), i-height/sqrt(3), height); + } else if (xPos<0){ + float xDiff = -xPos; + drawCrease(i, 0, 0, height - xDiff*sqrt(3)); + } else { + drawCrease(i, 0, i-height/sqrt(3), height); + } + + } + + // Exit the program + println("Finished."); + exit(); +} + +void drawCrease(float x1, float y1, float x2, float y2){ + if (dashedCreaseLines){ + float numDashesPerSide = 5; + float dashLength = triangleHeight*2/sqrt(3)/(numDashesPerSide*2); + dashedLine(x1, y1, x2, y2, dashLength, dashLength); + } else { + line(x1, y1, x2, y2); + } +} + +void dashedLine(float x1, float y1, float x2, float y2, float dashLength, float spaceLength){ + pushMatrix(); + translate(x1, y1); + rotate(atan2(y2-y1, x2-x1)); + float lineLength = sqrt((y2-y1)*(y2-y1) + (x2-x1)*(x2-x1)); + float partialDash = lineLength/(dashLength+spaceLength) - floor(lineLength/(dashLength+spaceLength)); + println(partialDash); + for (float i=(partialDash+spaceLength)/2;i<lineLength;i+=dashLength+spaceLength){ + line(i, 0, i+dashLength, 0); + } + popMatrix(); +} diff --git a/README.md b/README.md index 63b1975fb52bf7e7fb883ffb30fa332e9534ed7c..68de94c5915d71f8b25e6f809080fff869ce8765 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OrigamiSimulator -Live demo at <a href="http://git.amandaghassaei.com/OrigamiSimulator">git.amandaghassaei.com/OrigamiSimulator</a><br/> +Live demo at <a href="http://apps.amandaghassaei.com/OrigamiSimulator">apps.amandaghassaei.com/OrigamiSimulator</a><br/> <img src="crane.gif" />