# # logs.py # make lincoln logs, based on svg code from gik.py # edit doIt() to change the numbers of different kinds of logs. # set w to the appropriate width for the cardboard. # use testPiece to try out 6 widths at once. # from math import * w = 0.1 # slot width HUGE = 1e10 #draws all, including origin point. def drawSlot(originX, originY, slotDepth, slotWidth, chamfor, down, rightwards): xpath[-1].append(originX) ypath[-1].append(originY) chamforX = chamfor chamforY = chamfor if(not down): chamforY = -chamforY slotDepth = -slotDepth if(not rightwards): chamforX = -chamforX slotWidth = -slotWidth xpath[-1].append(originX + chamforX) ypath[-1].append(originY - chamforY) xpath[-1].append(originX + chamforX) ypath[-1].append(originY - slotDepth) xpath[-1].append(originX + chamforX+slotWidth) ypath[-1].append(originY - slotDepth) xpath[-1].append(originX + chamforX+slotWidth) ypath[-1].append(originY - chamforX) xpath[-1].append(originX + chamforX+slotWidth+chamforX) ypath[-1].append(originY) def testPiece(originX, originY, length, width, slotLength, slotWidthMin, slotWidthMax): xpath.append([]) ypath.append([]) chamfor = slotWidthMin / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) slotWidth = slotWidthMin slotInc = (slotWidthMax - slotWidthMin) / 5 slotInset = 0.2 #start of camphor drawSlot(originX+slotInset, originY+width, slotLength, slotWidth, chamfor, True, True) slotWidth += slotInc drawSlot(originX+length/2-slotWidth/2-chamfor, originY+width, slotLength, slotWidth, chamfor, True, True) slotWidth += slotInc drawSlot(originX + length - 2*chamfor - slotInset - slotWidth, originY+width, slotLength, slotWidth, chamfor, True, True) slotWidth += slotInc #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) drawSlot(originX + length - slotInset, originY, slotLength, slotWidth, chamfor, False, False) slotWidth += slotInc drawSlot(originX + length/2 + slotWidth/2+chamfor, originY, slotLength, slotWidth, chamfor, False, False) slotWidth += slotInc drawSlot(originX + slotInset + slotWidth + 2*chamfor, originY, slotLength, slotWidth, chamfor, False, False) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #origin is minX, minY. #slot inset is dist from end to start of slot camphor def oneSidePiece(originX, originY, length, width, slotLength, slotWidth, slotInset): xpath.append([]) ypath.append([]) width = 0.5 * width chamfor = slotWidth / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) #start of camphor drawSlot(originX+slotInset, originY+width, slotLength, slotWidth, chamfor, True, True) drawSlot(originX + length - 2*chamfor - slotInset - slotWidth, originY+width, slotLength, slotWidth, chamfor, True, True) #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) #drawSlot(originX + length - slotInset, originY, slotLength, slotWidth, chamfor, False, False) #drawSlot(originX + slotInset + slotWidth + 2*chamfor, originY, slotLength, slotWidth, chamfor, False, False) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #origin is minX, minY. #slot inset is dist from end to start of slot camphor def standardPiece(originX, originY, length, width, slotLength, slotWidth, slotInset): xpath.append([]) ypath.append([]) chamfor = slotWidth / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) #start of camphor drawSlot(originX+slotInset, originY+width, slotLength, slotWidth, chamfor, True, True) drawSlot(originX + length - 2*chamfor - slotInset - slotWidth, originY+width, slotLength, slotWidth, chamfor, True, True) #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) drawSlot(originX + length - slotInset, originY, slotLength, slotWidth, chamfor, False, False) drawSlot(originX + slotInset + slotWidth + 2*chamfor, originY, slotLength, slotWidth, chamfor, False, False) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #origin is minX, minY. #slot inset is dist from end to start of slot camphor def standardPieceWCut(originX, originY, length, width, slotLength, slotWidth, slotInset): xpath.append([]) ypath.append([]) chamfor = slotWidth / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) #start of camphor drawSlot(originX+slotInset, originY+width, slotLength, slotWidth, chamfor, True, True) drawSlot(originX + length - 2*chamfor - slotInset - slotWidth, originY+width, slotLength, slotWidth, chamfor, True, True) #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) drawSlot(originX + length - slotInset, originY, slotLength, slotWidth, chamfor, False, False) drawSlot(originX + length/2.0 + slotWidth/2.0 + chamfor, originY, slotLength, slotWidth, chamfor, False, False) drawSlot(originX + slotInset + slotWidth + 2*chamfor, originY, slotLength, slotWidth, chamfor, False, False) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) def oneSidePieceWCut(originX, originY, length, width, slotLength, slotWidth, slotInset): xpath.append([]) ypath.append([]) width = width /2.0 chamfor = slotWidth / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) #start of camphor #drawSlot(originX+slotInset, originY+width, slotLength, slotWidth, chamfor, True, True) #drawSlot(originX + length - 2*chamfor - slotInset - slotWidth, originY+width, slotLength, slotWidth, chamfor, True, True) #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) drawSlot(originX + length - slotInset, originY, slotLength, slotWidth, chamfor, False, False) drawSlot(originX + length/2.0 + slotWidth/2.0 + chamfor, originY, slotLength, slotWidth, chamfor, False, False) drawSlot(originX + slotInset + slotWidth + 2*chamfor, originY, slotLength, slotWidth, chamfor, False, False) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #origin is minX, minY. def singlePiece(originX, originY, length, width, slotLength, slotWidth): xpath.append([]) ypath.append([]) chamfor = slotWidth / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) drawSlot(originX+(length/2.0)-(slotWidth/2.0)-chamfor, originY+width, slotLength, slotWidth, chamfor, True, True) #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) drawSlot(originX + (length/2.0) + (slotWidth/2.0) + chamfor, originY, slotLength, slotWidth, chamfor, False, False) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #angle is from verticle. must be 45 def rafter(originX, originY, length, plankWidth, slotWidth, plankInset): xpath.append([]) ypath.append([]) plankAngle = pi/4.0 width = cos(plankAngle) * plankWidth chamfor = slotWidth / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) xpath[-1].append(originX + plankInset - (0.5*slotWidth) / cos(plankAngle) -chamfor * sin(plankAngle)) ypath[-1].append(originY + width) xpath[-1].append(originX + plankInset - (0.5*slotWidth) / cos(plankAngle) -chamfor * sin(plankAngle)) ypath[-1].append(originY + width - chamfor * cos(plankAngle)) bottomCenterX = originX + plankInset - 0.25*plankWidth * cos(pi/2 - plankAngle) bottomCenterY = originY + width - 0.25*plankWidth * sin(pi/2 - plankAngle) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY + cos(pi/2 - plankAngle)*(slotWidth/2.0)) #xpath[-1].append(originX + plankInset - bottomCenterX) #ypath[-1].append(originY + width - bottomCenterY) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY - cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(originX + plankInset + (0.5*slotWidth) / cos(plankAngle)) ypath[-1].append(originY + width) xpath[-1].append(originX + length - plankInset - (0.5*slotWidth) / cos(plankAngle)) ypath[-1].append(originY + width) bottomCenterX = originX + length - plankInset + 0.25*plankWidth * cos(pi/2 - plankAngle) bottomCenterY = originY + width - 0.25*plankWidth * sin(pi/2 - plankAngle) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY - cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY + cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(originX + length - plankInset + (0.5*slotWidth) / cos(plankAngle) +chamfor * sin(plankAngle)) ypath[-1].append(originY + width - chamfor * cos(plankAngle)) xpath[-1].append(originX + length - plankInset + (0.5*slotWidth) / cos(plankAngle) +chamfor * sin(plankAngle)) ypath[-1].append(originY + width) #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) #plankInset for bottom plankInset = plankInset - (width * tan(plankAngle)) xpath[-1].append(originX + length - plankInset + (0.5*slotWidth) / cos(plankAngle)) ypath[-1].append(originY) bottomCenterX = originX + length - plankInset - 0.25*plankWidth * cos(pi/2 - plankAngle) bottomCenterY = originY + 0.25*plankWidth * sin(pi/2 - plankAngle) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY + cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY - cos(pi/2 - plankAngle)*(slotWidth/2.0)) #xpath[-1].append(originX + length - plankInset - (0.5*slotWidth) / cos(plankAngle) - chamfor * sin(plankAngle)) #ypath[-1].append(originY + chamfor * cos(plankAngle)) #xpath[-1].append(originX + length - plankInset - (0.5*slotWidth) / cos(plankAngle) - chamfor * sin(plankAngle)) #ypath[-1].append(originY) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(originY+chamfor) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0) - chamfor) ypath[-1].append(originY) bottomCenterX = originX + plankInset + 0.25*plankWidth * cos(pi/2 - plankAngle) bottomCenterY = originY + 0.25*plankWidth * sin(pi/2 - plankAngle) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0) + chamfor) ypath[-1].append(originY) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(originY + chamfor) #xpath[-1].append(originX + plankInset + (0.5*slotWidth) / cos(plankAngle) + chamfor * sin(plankAngle)) #ypath[-1].append(originY) #xpath[-1].append(originX + plankInset + (0.5*slotWidth) / cos(plankAngle) + chamfor * sin(plankAngle)) #ypath[-1].append(originY + chamfor * cos(plankAngle)) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY - cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY + cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(originX + plankInset - (0.5*slotWidth) / cos(plankAngle)) ypath[-1].append(originY) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #angle is from verticle. must be 45 def rafterTransition(originX, originY, length, width, slotWidth, plankInset, plankInsetBelow, slotLengthBelow): xpath.append([]) ypath.append([]) plankAngle = pi/4.0 chamfor = slotWidth / 5.0 #bottom left xpath[-1].append(originX) ypath[-1].append(originY) #top left xpath[-1].append(originX) ypath[-1].append(originY + width) xpath[-1].append(originX + plankInset - (0.5*slotWidth) / cos(plankAngle) -chamfor * sin(plankAngle)) ypath[-1].append(originY + width) xpath[-1].append(originX + plankInset - (0.5*slotWidth) / cos(plankAngle) -chamfor * sin(plankAngle)) ypath[-1].append(originY + width - chamfor * cos(plankAngle)) bottomCenterX = originX + plankInset - 0.25*width * cos(pi/2 - plankAngle) bottomCenterY = originY + width - 0.25*width * sin(pi/2 - plankAngle) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY + cos(pi/2 - plankAngle)*(slotWidth/2.0)) #xpath[-1].append(originX + plankInset - bottomCenterX) #ypath[-1].append(originY + width - bottomCenterY) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY - cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(originX + plankInset + (0.5*slotWidth) / cos(plankAngle)) ypath[-1].append(originY + width) xpath[-1].append(originX + length - plankInset - (0.5*slotWidth) / cos(plankAngle)) ypath[-1].append(originY + width) bottomCenterX = originX + length - plankInset + 0.25*width * cos(pi/2 - plankAngle) bottomCenterY = originY + width - 0.25*width * sin(pi/2 - plankAngle) xpath[-1].append(bottomCenterX - sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY - cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(bottomCenterX + sin(pi/2 - plankAngle)*(slotWidth/2.0)) ypath[-1].append(bottomCenterY + cos(pi/2 - plankAngle)*(slotWidth/2.0)) xpath[-1].append(originX + length - plankInset + (0.5*slotWidth) / cos(plankAngle) +chamfor * sin(plankAngle)) ypath[-1].append(originY + width - chamfor * cos(plankAngle)) xpath[-1].append(originX + length - plankInset + (0.5*slotWidth) / cos(plankAngle) +chamfor * sin(plankAngle)) ypath[-1].append(originY + width) #top right xpath[-1].append(originX + length) ypath[-1].append(originY + width) #bottom right xpath[-1].append(originX + length) ypath[-1].append(originY) drawSlot(originX + length - plankInsetBelow, originY, slotLengthBelow, slotWidth, chamfor, False, False) drawSlot(originX + plankInsetBelow + slotWidth + 2*chamfor, originY, slotLengthBelow, slotWidth, chamfor, False, False) #bottom left xpath[-1].append(originX) ypath[-1].append(originY) def svgwrite(xpath,ypath,filename): xmin = HUGE ymin = HUGE xmax = -HUGE ymax = -HUGE for piece in range(len(xpath)): for point in range(len(xpath[piece])): x = xpath[piece][point] y = ypath[piece][point] if (x < xmin): xmin = x if (x > xmax): xmax = x if (y < ymin): ymin = y if (y > ymax): ymax = y outfile = open(filename,"w") outfile.write('\n') outfile.write('\n') outfile.write('\n'\ %(xmax-xmin,ymax-ymin,xmin,ymin,xmax-xmin,ymax-ymin)) outfile.write('\n') for piece in range(len(xpath)): outfile.write('\n') outfile.write('\n') outfile.write('\n') outfile.close() x = 0 y = 0 def makeRafters(originX, originY, plankWidth, desiredSize, slotWidth): inset = 0.6 spread = (plankWidth/2) * cos(pi/4) * 2 length = spread + 2*inset rafter(originX, originY, length, plankWidth, slotWidth, inset) originY += plankWidth rafter(originX, originY, length, plankWidth, slotWidth, inset) while (spread < desiredSize): originY += plankWidth spread += sin(pi/4) * plankWidth * 2 length = spread + 2*inset print "originX=" + `originX` rafter(originX, originY, length, plankWidth, slotWidth, inset) originY += plankWidth rafter(originX, originY, length, plankWidth, slotWidth, inset) spread += sin(pi/4) * plankWidth * 2 length = spread + 2*inset originY += plankWidth rafterTransition(originX, originY, length, plankWidth, slotWidth, inset, (length - desiredSize)/2, plankWidth/4) originY += plankWidth*1.1 rafterTransition(originX, originY, length, plankWidth, slotWidth, inset, (length - desiredSize)/2, plankWidth/4) xpath = [] ypath = [] #standardPieceWCut(0, 0, 7, 0.5, 0.125, w, 0.3) #singlePiece(0, 0, 1, 0.5, 0.125, w) #rafter(0, 0, 5, 0.5, 0.1, 0.6) #rafterTransition(0, 0, 5, 0.5, 0.1, 0.8, 0.3, 0.125) #testPiece(0, 0, 4, 0.5, 0.125, 0.2, 0.3) def testIt(): scale = 1.0 smallSide = 5*scale largeSide = 8*scale width = 0.5*scale slotDepth = 0.125*scale inset = 0.3*scale #w = w*scale extraSmallSide = 1.5 * scale originX = 0 originY = 0 #makeRafters(originX, originY, width, smallSide - 2*inset, w) makeRafters(originX, originY, width, extraSmallSide - 2*inset, w) originX += smallSide for i in range (1, 3): standardPiece(originX, originY, extraSmallSide, width, slotDepth, w, inset) originY += width*1.1 for i in range (1, 2): standardPiece(originX, originY, largeSide / 2.0 + inset, width, slotDepth, w, inset) originY += width*1.1 #originY = 0 #originX += (largeSide / 2.0 + inset) * 1.1 for i in range (1, 2): standardPiece(originX, originY, smallSide, width, slotDepth, w, inset) originY += width*1.1 originY = 0 originX += smallSide * 1.1 for i in range (1, 4): singlePiece(originX, originY, 0.6*scale, width, slotDepth, w) originY += width*1.1 originY = 0 originX += 0.6 * 1.1 * scale for i in range (1, 2): standardPiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.1 standardPieceWCut(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.1 oneSidePiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += 0.5*width*1.1 #oneSidePiece(originX, originY, largeSide, width, slotDepth, w, inset) #originY += 0.5*width*1.1 def doIt(): scale = 0.5 smallSide = 5*scale largeSide = 8*scale width = 0.5*scale slotDepth = 0.125*scale inset = 0.3*scale #w = w*scale originX = 0 originY = 0 makeRafters(originX, originY, width, smallSide - 2*inset, w) originX += smallSide for i in range (1, 6): standardPiece(originX, originY, largeSide / 2.0 + inset + 0.5*w + 0.2*w, width, slotDepth, w, inset) originY += width*1.1 originY = 0 originX += (largeSide / 2.0 + inset) * 1.1 for i in range (1, 20): standardPiece(originX, originY, smallSide, width, slotDepth, w, inset) originY += width*1.1 originY = 0 originX += smallSide * 1.1 for i in range (1, 20): singlePiece(originX, originY, 0.6*scale, width, slotDepth, w) originY += width*1.1 originY = 0 originX += 0.6 * 1.1 * scale for i in range (1, 35): standardPiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.1 standardPieceWCut(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.1 oneSidePieceWCut(originX, originY, largeSide, width, slotDepth, w, inset) originY += 0.5*width*1.1 oneSidePiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += 0.5*width*1.1 oneSidePiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += 0.5*width*1.1 def tempIt(): scale = 1 smallSide = 5*scale largeSide = 8*scale width = 0.5*scale slotDepth = 0.125*scale inset = 0.3*scale #w = w*scale originX = 0 originY = 0 #makeRafters(originX, originY, width, smallSide - 2*inset, w) originX += smallSide for i in range (1, 1): standardPiece(originX, originY, largeSide / 2.0 + inset + 0.5*w + 0.2*w, width, slotDepth, w, inset) originY += width*1.1 #originY = 0 #originX += (largeSide / 2.0 + inset) * 1.1 for i in range (1, 1): standardPiece(originX, originY, smallSide, width, slotDepth, w, inset) originY += width*1.1 #originY = 0 #originX += smallSide * 1.1 for i in range (1, 1): singlePiece(originX, originY, 0.6*scale, width, slotDepth, w) originY += width*1.1 #originY = 0 #originX += 0.6 * 1.1 * scale for i in range (1, 1): standardPiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.1 standardPieceWCut(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.3 oneSidePieceWCut(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.3 oneSidePiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += width*1.3 #oneSidePiece(originX, originY, largeSide, width, slotDepth, w, inset) originY += 0.5*width*1.1 tempIt() #doIt() #testIt() svgwrite(xpath,ypath,"out.svg") print "Logs written to out.svg"