Add command line parameter using argparse
Remove params from __init__() Added new function .open() that needs to be called from .render()
This commit is contained in:
parent
333c786a11
commit
40d011db6a
2
TODO.txt
2
TODO.txt
|
@ -6,3 +6,5 @@
|
||||||
* finish lamp
|
* finish lamp
|
||||||
* Make settings nicer
|
* Make settings nicer
|
||||||
* offer a collection of different settings
|
* offer a collection of different settings
|
||||||
|
* Make bolts configurable (e.g. box2.py)
|
||||||
|
* Make flextest.py pattern configurable
|
||||||
|
|
18
box.py
18
box.py
|
@ -17,13 +17,17 @@
|
||||||
from boxes import *
|
from boxes import *
|
||||||
|
|
||||||
class Box(Boxes):
|
class Box(Boxes):
|
||||||
def __init__(self, x, y, h, **kw):
|
def __init__(self):
|
||||||
self.x, self.y, self.h = x, y, h
|
Boxes.__init__(self)
|
||||||
Boxes.__init__(self, width=x+y+40, height=y+2*h+50, **kw)
|
self.buildArgParser("x", "y", "h")
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, h = self.x, self.y, self.h
|
x, y, h = self.x, self.y, self.h
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
self.open(width=x+y+40, height=y+2*h+50)
|
||||||
|
|
||||||
|
b.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||||
|
surroundingspaces=1)
|
||||||
|
|
||||||
d2 = [Bolts(2)]
|
d2 = [Bolts(2)]
|
||||||
d3 = [Bolts(3)]
|
d3 = [Bolts(3)]
|
||||||
|
@ -41,7 +45,7 @@ class Box(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
b = Box(140, 202, 50, thickness=4.0)
|
if __name__ == '__main__':
|
||||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
b = Box()
|
||||||
surroundingspaces=1)
|
b.parseArgs()
|
||||||
b.render()
|
b.render()
|
||||||
|
|
17
box2.py
17
box2.py
|
@ -18,13 +18,16 @@ from boxes import *
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
class Box(Boxes):
|
class Box(Boxes):
|
||||||
def __init__(self, x, y, h, **kw):
|
def __init__(self):
|
||||||
self.x, self.y, self.h = x, y, h
|
Boxes.__init__(self)
|
||||||
Boxes.__init__(self, width=x+y+40, height=y+2*h+50, **kw)
|
self.buildArgParser("x", "y", "h")
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, h = self.x, self.y, self.h
|
x, y, h = self.x, self.y, self.h
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
self.open(width=x+y+40, height=y+2*h+50)
|
||||||
|
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||||
|
surroundingspaces=1)
|
||||||
|
|
||||||
d2 = [Bolts(2)]
|
d2 = [Bolts(2)]
|
||||||
d3 = [Bolts(3)]
|
d3 = [Bolts(3)]
|
||||||
|
@ -41,7 +44,7 @@ class Box(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
b = Box(200, 200, 200, thickness=4.0)
|
if __name__ == '__main__':
|
||||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
b = Box()
|
||||||
surroundingspaces=1)
|
b.parseArgs()
|
||||||
b.render()
|
b.render()
|
||||||
|
|
20
box3.py
20
box3.py
|
@ -17,14 +17,19 @@
|
||||||
from boxes import *
|
from boxes import *
|
||||||
|
|
||||||
class Box(Boxes):
|
class Box(Boxes):
|
||||||
def __init__(self, x, y, h, **kw):
|
def __init__(self):
|
||||||
self.x, self.y, self.h = x, y, h
|
Boxes.__init__(self)
|
||||||
Boxes.__init__(self, width=x+y+40, height=y+2*h+50, **kw)
|
self.buildArgParser("x", "y", "h")
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, h = self.x, self.y, self.h
|
x, y, h = self.x, self.y, self.h
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
|
||||||
|
self.open(width=x+y+10*t, height=y+h+10*t)
|
||||||
|
|
||||||
|
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||||
|
surroundingspaces=1)
|
||||||
|
|
||||||
d2 = [Bolts(2)]
|
d2 = [Bolts(2)]
|
||||||
d3 = [Bolts(3)]
|
d3 = [Bolts(3)]
|
||||||
|
|
||||||
|
@ -41,8 +46,7 @@ class Box(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
t = 6.0
|
if __name__ == '__main__':
|
||||||
b = Box(380-2*t, 370-2*t, 120-t, thickness=t)
|
b = Box()
|
||||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
b.parseArgs()
|
||||||
surroundingspaces=1)
|
b.render()
|
||||||
b.render()
|
|
||||||
|
|
102
boxes.py
102
boxes.py
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
import cairo
|
import cairo
|
||||||
import math
|
import math
|
||||||
|
import argparse
|
||||||
|
import re
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
def dist(dx, dy):
|
def dist(dx, dy):
|
||||||
|
@ -494,21 +496,88 @@ class NutHole:
|
||||||
self.boxes.edge(side)
|
self.boxes.edge(side)
|
||||||
self.boxes.corner(-60)
|
self.boxes.corner(-60)
|
||||||
|
|
||||||
|
def argparseSections(s):
|
||||||
|
m = re.match(r"(\d+(\.\d+)?)/(\d+)", s)
|
||||||
|
if m:
|
||||||
|
n = int(m.group(3))
|
||||||
|
print([ float(m.group(1)) ] * n)
|
||||||
|
return [ float(m.group(1))/n ] * n
|
||||||
|
m = re.match(r"(\d+(\.\d+)?)\*(\d+)", s)
|
||||||
|
if m:
|
||||||
|
n = int(m.group(3))
|
||||||
|
return [ float(m.group(1)) ] * n
|
||||||
|
try:
|
||||||
|
return [float(part) for part in s.split(":")]
|
||||||
|
except ValueError:
|
||||||
|
raise argparse.ArgumentTypeError("Don't understand sections string")
|
||||||
|
|
||||||
class Boxes:
|
class Boxes:
|
||||||
|
|
||||||
def __init__(self, width=300, height=200, thickness=3.0, burn=0.05):
|
def __init__(self):
|
||||||
self.thickness = thickness
|
self.argparser = argparse.ArgumentParser()
|
||||||
self.burn = burn
|
self.argparser.add_argument(
|
||||||
|
"--thickness", action="store", type=float, default=4.0,
|
||||||
|
help="thickness of the material")
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--output", action="store", type=str, default="box.svg",
|
||||||
|
help="name of resulting file")
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--debug", action="store_true", default=False,
|
||||||
|
help="print surrounding boxes for some structures")
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--burn", action="store", type=float, default=0.05,
|
||||||
|
help="burn correction in mm")
|
||||||
|
|
||||||
|
def open(self, width, height):
|
||||||
self.spacing = 2*self.burn + 0.5 * self.thickness
|
self.spacing = 2*self.burn + 0.5 * self.thickness
|
||||||
|
|
||||||
self.fingerHoleEdgeWidth = 1.0 # multitudes of self.thickness
|
self.fingerHoleEdgeWidth = 1.0 # multitudes of self.thickness
|
||||||
self.bedBoltSettings = (3, 5.5, 2, 20, 15) #d, d_nut, h_nut, l, l1
|
self.bedBoltSettings = (3, 5.5, 2, 20, 15) #d, d_nut, h_nut, l, l1
|
||||||
self.hexHolesSettings = (5, 3, 'circle') # r, dist, style
|
self.hexHolesSettings = (5, 3, 'circle') # r, dist, style
|
||||||
self.output = "box.svg"
|
|
||||||
self.debug = 0
|
|
||||||
self._init_surface(width, height)
|
self._init_surface(width, height)
|
||||||
self._buildObjects()
|
self._buildObjects()
|
||||||
|
|
||||||
|
def buildArgParser(self, *l):
|
||||||
|
for arg in l:
|
||||||
|
if arg == "x":
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--x", action="store", type=float, default=100.0,
|
||||||
|
help="inner width in mm")
|
||||||
|
elif arg == "y":
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--y", action="store", type=float, default=100.0,
|
||||||
|
help="inner depth in mm")
|
||||||
|
elif arg == "sx":
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--sx", action="store", type=argparseSections,
|
||||||
|
default="50*3",
|
||||||
|
help="""Sections left to right in mm
|
||||||
|
Possible formats:
|
||||||
|
* overallwidth/numberof sections e.g. "250/5"
|
||||||
|
* sectionwith*numberofsections e.g. "50*5"
|
||||||
|
* section widths separated by : e.g. "30:25.5:70"
|
||||||
|
""")
|
||||||
|
elif arg == "sy":
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--sy", action="store", type=argparseSections,
|
||||||
|
default="50*3",
|
||||||
|
help="""Sections back to front in mm
|
||||||
|
|
||||||
|
See --sy for format""")
|
||||||
|
elif arg == "h":
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--h", action="store", type=float, default=100.0,
|
||||||
|
help="inner height in mm")
|
||||||
|
elif arg == "hi":
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--hi", action="store", type=float, default=None,
|
||||||
|
help="inner height of inner walls in mm")
|
||||||
|
else:
|
||||||
|
raise ValueError("No default for argument", arg)
|
||||||
|
|
||||||
|
def parseArgs(self):
|
||||||
|
self.argparser.parse_args(namespace=self)
|
||||||
|
|
||||||
def addPart(self, part, name=None):
|
def addPart(self, part, name=None):
|
||||||
if name is None:
|
if name is None:
|
||||||
name = part.__class__.__name__
|
name = part.__class__.__name__
|
||||||
|
@ -1111,17 +1180,25 @@ class Boxes:
|
||||||
### main
|
### main
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
def render(self, x, y, h):
|
class DemoBox(Boxes):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
Boxes.__init__(self)
|
||||||
|
self.buildArgParser("x", "y", "h")
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
x, y, h, t = self.x, self.y, self.h, self.thickness
|
||||||
|
self.open(2*x+10*self.thickness, y+2*h+20*self.thickness)
|
||||||
self.ctx.save()
|
self.ctx.save()
|
||||||
|
|
||||||
self.moveTo(10, 10)
|
self.moveTo(t, t)
|
||||||
self.roundedPlate(x, y, 0)
|
self.rectangularWall(x, y, "ffff")
|
||||||
self.moveTo(x+40, 0)
|
self.moveTo(x+4*t, 0)
|
||||||
self.rectangularWall(x, y, "FFFF")
|
self.rectangularWall(x, y, "FFFF")
|
||||||
|
|
||||||
self.ctx.restore()
|
self.ctx.restore()
|
||||||
|
|
||||||
self.moveTo(10, y+20)
|
self.moveTo(t, y+4*t)
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
for l in (x, y):
|
for l in (x, y):
|
||||||
self.rectangularWall(l, h, "hffF")
|
self.rectangularWall(l, h, "hffF")
|
||||||
|
@ -1132,5 +1209,6 @@ class Boxes:
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
b = Boxes(900, 700)
|
b = DemoBox()
|
||||||
b.render(100, 161.8, 120)
|
b.parseArgs()
|
||||||
|
b.render()
|
||||||
|
|
12
castle.py
12
castle.py
|
@ -19,7 +19,10 @@ from boxes import *
|
||||||
class Castle(Boxes):
|
class Castle(Boxes):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self, 800, 600)
|
Boxes.__init__(self)
|
||||||
|
|
||||||
|
def render(self, t_x=70, t_h=250, w1_x=300, w1_h=120, w2_x=100, w2_h=120):
|
||||||
|
self.open(800, 600)
|
||||||
s = FingerJointSettings(self.thickness, relative=False,
|
s = FingerJointSettings(self.thickness, relative=False,
|
||||||
space = 10, finger=10, height=10,
|
space = 10, finger=10, height=10,
|
||||||
width=self.thickness)
|
width=self.thickness)
|
||||||
|
@ -30,7 +33,6 @@ class Castle(Boxes):
|
||||||
P.char = "P"
|
P.char = "P"
|
||||||
self.addPart(P)
|
self.addPart(P)
|
||||||
|
|
||||||
def render(self, t_x=70, t_h=250, w1_x=300, w1_h=120, w2_x=100, w2_h=120):
|
|
||||||
self.moveTo(0,0)
|
self.moveTo(0,0)
|
||||||
self.rectangularWall(t_x, t_h, edges="efPf", move="right", callback=
|
self.rectangularWall(t_x, t_h, edges="efPf", move="right", callback=
|
||||||
[lambda: self.fingerHolesAt(t_x*0.5, 0, w1_h, 90),])
|
[lambda: self.fingerHolesAt(t_x*0.5, 0, w1_h, 90),])
|
||||||
|
@ -44,5 +46,7 @@ class Castle(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
c = Castle()
|
if __name__ == '__main__':
|
||||||
c.render()
|
c = Castle()
|
||||||
|
c.parseArgs()
|
||||||
|
c.render()
|
||||||
|
|
17
drillbox.py
17
drillbox.py
|
@ -17,10 +17,9 @@
|
||||||
from boxes import *
|
from boxes import *
|
||||||
|
|
||||||
class Box(Boxes):
|
class Box(Boxes):
|
||||||
def __init__(self, x, y, h, **kw):
|
def __init__(self, x, y, h):
|
||||||
|
Boxes.__init__(self)
|
||||||
self.x, self.y, self.h = x, y, h
|
self.x, self.y, self.h = x, y, h
|
||||||
Boxes.__init__(self, width=x+y+40, height=3*y+2*h+50, **kw)
|
|
||||||
|
|
||||||
|
|
||||||
def holesx(self):
|
def holesx(self):
|
||||||
self.fingerHolesAt(0, 5, self.x, angle=0)
|
self.fingerHolesAt(0, 5, self.x, angle=0)
|
||||||
|
@ -52,6 +51,10 @@ class Box(Boxes):
|
||||||
x, y, h = self.x, self.y, self.h
|
x, y, h = self.x, self.y, self.h
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
|
||||||
|
self.open(width=x+y+40, height=3*y+2*h+16*t)
|
||||||
|
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||||
|
surroundingspaces=1)
|
||||||
|
|
||||||
self.moveTo(t, t)
|
self.moveTo(t, t)
|
||||||
self.rectangularWall(x, h, "FfeF", callback=[self.holesx],move="right")
|
self.rectangularWall(x, h, "FfeF", callback=[self.holesx],move="right")
|
||||||
self.rectangularWall(y, h, "FfeF", callback=[self.holesy], move="up")
|
self.rectangularWall(y, h, "FfeF", callback=[self.holesy], move="up")
|
||||||
|
@ -68,7 +71,7 @@ class Box(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
b = Box(120, 240, 60, thickness=4.0)
|
if __name__ == '__main__':
|
||||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
b = Box(120, 240, 60)
|
||||||
surroundingspaces=1)
|
b.parseArgs()
|
||||||
b.render()
|
b.render()
|
||||||
|
|
50
flexbox.py
50
flexbox.py
|
@ -18,17 +18,12 @@ import boxes
|
||||||
import math
|
import math
|
||||||
|
|
||||||
class FlexBox(boxes.Boxes):
|
class FlexBox(boxes.Boxes):
|
||||||
def __init__(self, x, y, z, r=None, thickness=3.0):
|
def __init__(self):
|
||||||
c4 = math.pi * r * 0.5
|
boxes.Boxes.__init__(self)
|
||||||
self.x = x
|
self.buildArgParser("x", "y", "h")
|
||||||
self.y = y
|
self.argparser.add_argument(
|
||||||
self.z = z
|
"--radius", action="store", type=float, default=15,
|
||||||
self.r = r or min(x, y)/2.0
|
help="Radius of the latch in mm")
|
||||||
self.latchsize = 8*thickness
|
|
||||||
|
|
||||||
width = 2*x + 2*y - 8*r + 4*c4 + 4*thickness
|
|
||||||
height = y + z + 4*thickness
|
|
||||||
boxes.Boxes.__init__(self, width, height, thickness=thickness)
|
|
||||||
|
|
||||||
@boxes.restore
|
@boxes.restore
|
||||||
def flexBoxSide(self, x, y, r, callback=None):
|
def flexBoxSide(self, x, y, r, callback=None):
|
||||||
|
@ -47,20 +42,20 @@ class FlexBox(boxes.Boxes):
|
||||||
self.corner(90, r)
|
self.corner(90, r)
|
||||||
|
|
||||||
def surroundingWall(self):
|
def surroundingWall(self):
|
||||||
x, y, z, r = self.x, self.y, self.z, self.r
|
x, y, h, r = self.x, self.y, self.h, self.radius
|
||||||
|
|
||||||
c4 = math.pi * r * 0.5
|
c4 = math.pi * r * 0.5
|
||||||
|
|
||||||
self.edges["F"](y-2*r-self.latchsize, False)
|
self.edges["F"](y-2*r-self.latchsize, False)
|
||||||
self.flexEdge(c4, z+2*self.thickness)
|
self.flexEdge(c4, h+2*self.thickness)
|
||||||
self.edges["F"](x-2*r, False)
|
self.edges["F"](x-2*r, False)
|
||||||
self.flexEdge(c4, z+2*self.thickness)
|
self.flexEdge(c4, h+2*self.thickness)
|
||||||
self.edges["F"](y-2*r, False)
|
self.edges["F"](y-2*r, False)
|
||||||
self.flexEdge(c4, z+2*self.thickness)
|
self.flexEdge(c4, h+2*self.thickness)
|
||||||
self.edge(x-2*r)
|
self.edge(x-2*r)
|
||||||
self.flexEdge(c4, z+2*self.thickness)
|
self.flexEdge(c4, h+2*self.thickness)
|
||||||
self.latch(self.latchsize, False)
|
self.latch(self.latchsize, False)
|
||||||
self.edge(z+2*self.thickness)
|
self.edge(h+2*self.thickness)
|
||||||
self.latch(self.latchsize, False, True)
|
self.latch(self.latchsize, False, True)
|
||||||
self.edge(c4)
|
self.edge(c4)
|
||||||
self.edge(x-2*r)
|
self.edge(x-2*r)
|
||||||
|
@ -71,20 +66,31 @@ class FlexBox(boxes.Boxes):
|
||||||
self.edge(c4)
|
self.edge(c4)
|
||||||
self.edges["F"](y-2*r-self.latchsize, False)
|
self.edges["F"](y-2*r-self.latchsize, False)
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
self.edge(z+2*self.thickness)
|
self.edge(h+2*self.thickness)
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
|
x, y, h = self.x, self.y, self.h
|
||||||
|
r = self.radius or min(x, y)/2.0
|
||||||
|
self.latchsize = 8 * self.thickness
|
||||||
|
c4 = math.pi * r * 0.5
|
||||||
|
|
||||||
|
width = 2*x + 2*y - 8*r + 4*c4 + 4*self.thickness
|
||||||
|
height = y + h + 8*self.thickness
|
||||||
|
|
||||||
|
self.open(width, height)
|
||||||
|
|
||||||
self.moveTo(self.thickness, self.thickness)
|
self.moveTo(self.thickness, self.thickness)
|
||||||
self.surroundingWall()
|
self.surroundingWall()
|
||||||
self.moveTo(self.thickness, self.z+4*self.thickness)
|
self.moveTo(self.thickness, self.h+5*self.thickness)
|
||||||
self.flexBoxSide(self.x, self.y, self.r)
|
self.flexBoxSide(self.x, self.y, self.radius)
|
||||||
self.moveTo(2*self.x+3*self.thickness, 0)
|
self.moveTo(2*self.x+3*self.thickness, 0)
|
||||||
self.ctx.scale(-1, 1)
|
self.ctx.scale(-1, 1)
|
||||||
self.flexBoxSide(self.x, self.y, self.r)
|
self.flexBoxSide(self.x, self.y, self.radius)
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
b = FlexBox(50, 70, 50, r=15)
|
b = FlexBox()
|
||||||
|
b.parseArgs()
|
||||||
b.render()
|
b.render()
|
||||||
|
|
57
flexbox2.py
57
flexbox2.py
|
@ -18,19 +18,12 @@ from boxes import *
|
||||||
import math
|
import math
|
||||||
|
|
||||||
class FlexBox(Boxes):
|
class FlexBox(Boxes):
|
||||||
def __init__(self, x, y, z, r=None, thickness=3.0):
|
def __init__(self):
|
||||||
self.x = x
|
Boxes.__init__(self)
|
||||||
self.y = y
|
self.buildArgParser("x", "y", "h")
|
||||||
self.z = z
|
self.argparser.add_argument(
|
||||||
self.r = r or min(x, y)/2.0
|
"--radius", action="store", type=float, default=15,
|
||||||
self.c4 = c4 = math.pi * r * 0.5
|
help="Radius of the corners in mm")
|
||||||
self.latchsize = 8*thickness
|
|
||||||
|
|
||||||
width = 2*x + y - 3*r + 2*c4 + 7*thickness + self.latchsize # lock
|
|
||||||
height = y + z + 8*thickness
|
|
||||||
|
|
||||||
Boxes.__init__(self, width, height, thickness=thickness)
|
|
||||||
self.fingerJointSettings = (4, 4)
|
|
||||||
|
|
||||||
@restore
|
@restore
|
||||||
def flexBoxSide(self, x, y, r, callback=None):
|
def flexBoxSide(self, x, y, r, callback=None):
|
||||||
|
@ -50,17 +43,17 @@ class FlexBox(Boxes):
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
|
|
||||||
def surroundingWall(self):
|
def surroundingWall(self):
|
||||||
x, y, z, r = self.x, self.y, self.z, self.r
|
x, y, h, r = self.x, self.y, self.h, self.radius
|
||||||
|
|
||||||
self.edges["F"](y-r, False)
|
self.edges["F"](y-r, False)
|
||||||
if (x-2*r < 0.1):
|
if (x-2*r < 0.1):
|
||||||
self.flexEdge(2*self.c4, z+2*self.thickness)
|
self.flexEdge(2*self.c4, h+2*self.thickness)
|
||||||
else:
|
else:
|
||||||
self.flexEdge(self.c4, z+2*self.thickness)
|
self.flexEdge(self.c4, h+2*self.thickness)
|
||||||
self.edge(x-2*r)
|
self.edge(x-2*r)
|
||||||
self.flexEdge(self.c4, z+2*self.thickness)
|
self.flexEdge(self.c4, h+2*self.thickness)
|
||||||
self.latch(self.latchsize, False)
|
self.latch(self.latchsize, False)
|
||||||
self.edge(z+2*self.thickness)
|
self.edge(h+2*self.thickness)
|
||||||
self.latch(self.latchsize, False, True)
|
self.latch(self.latchsize, False, True)
|
||||||
self.edge(self.c4)
|
self.edge(self.c4)
|
||||||
self.edge(x-2*r)
|
self.edge(x-2*r)
|
||||||
|
@ -68,28 +61,40 @@ class FlexBox(Boxes):
|
||||||
self.edges["F"](y-r)
|
self.edges["F"](y-r)
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
self.edge(self.thickness)
|
self.edge(self.thickness)
|
||||||
self.edges["f"](z)
|
self.edges["f"](h)
|
||||||
self.edge(self.thickness)
|
self.edge(self.thickness)
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
|
self.radius = self.radius or min(x, y)/2.0
|
||||||
|
self.c4 = c4 = math.pi * self.radius * 0.5
|
||||||
|
self.latchsize = 8*self.thickness
|
||||||
|
|
||||||
|
width = 2*self.x + self.y - 3*self.radius + 2*c4 + 7*self.thickness + self.latchsize # lock
|
||||||
|
height = self.y + self.h + 8*self.thickness
|
||||||
|
|
||||||
|
self.open(width, height)
|
||||||
|
|
||||||
|
self.fingerJointSettings = (4, 4)
|
||||||
|
|
||||||
self.moveTo(2*self.thickness, self.thickness)
|
self.moveTo(2*self.thickness, self.thickness)
|
||||||
self.ctx.save()
|
self.ctx.save()
|
||||||
self.surroundingWall()
|
self.surroundingWall()
|
||||||
self.moveTo(self.x+self.y-3*self.r+2*self.c4+self.latchsize+1*self.thickness, 0)
|
self.moveTo(self.x+self.y-3*self.radius+2*self.c4+self.latchsize+1*self.thickness, 0)
|
||||||
self.rectangularWall(self.x, self.z, edges="FFFF")
|
self.rectangularWall(self.x, self.h, edges="FFFF")
|
||||||
self.ctx.restore()
|
self.ctx.restore()
|
||||||
self.moveTo(0, self.z+4*self.thickness)
|
self.moveTo(0, self.h+4*self.thickness)
|
||||||
self.flexBoxSide(self.x, self.y, self.r)
|
self.flexBoxSide(self.x, self.y, self.radius)
|
||||||
self.moveTo(2*self.x+3*self.thickness, 0)
|
self.moveTo(2*self.x+3*self.thickness, 0)
|
||||||
self.ctx.scale(-1, 1)
|
self.ctx.scale(-1, 1)
|
||||||
self.flexBoxSide(self.x, self.y, self.r)
|
self.flexBoxSide(self.x, self.y, self.radius)
|
||||||
self.ctx.scale(-1, 1)
|
self.ctx.scale(-1, 1)
|
||||||
self.moveTo(2*self.thickness, 0)
|
self.moveTo(2*self.thickness, 0)
|
||||||
self.rectangularWall(self.z, self.y-self.r-self.latchsize, edges="fFeF")
|
self.rectangularWall(self.h, self.y-self.radius-self.latchsize, edges="fFeF")
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
b = FlexBox(70, 100, 70, r=30, thickness=3.0)
|
b = FlexBox()
|
||||||
|
b.parseArgs()
|
||||||
b.render()
|
b.render()
|
||||||
|
|
69
flexbox3.py
69
flexbox3.py
|
@ -18,31 +18,22 @@ from boxes import *
|
||||||
import math
|
import math
|
||||||
|
|
||||||
class FlexBox(Boxes):
|
class FlexBox(Boxes):
|
||||||
def __init__(self, x, y, z, r=None, d=1.0, h=5.0, thickness=3.0):
|
def __init__(self):
|
||||||
self.x = x
|
Boxes.__init__(self)
|
||||||
self.y = y
|
self.buildArgParser("x", "y")
|
||||||
self.z = z
|
self.argparser.add_argument(
|
||||||
self.r = r or min(x, y)/2.0
|
"--z", action="store", type=float, default=100.0,
|
||||||
self.d = d
|
help="height of the box")
|
||||||
self.h = h
|
self.argparser.add_argument(
|
||||||
self.c4 = c4 = math.pi * r * 0.5 * 0.95
|
"--h", action="store", type=float, default=10.0,
|
||||||
self.latchsize = 8*thickness
|
help="height of the lid")
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--radius", action="store", type=float, default=10.0,
|
||||||
|
help="radius of the lids living hinge")
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--c", action="store", type=float, default=1.0,
|
||||||
|
dest="d", help="clearance of the lid")
|
||||||
|
|
||||||
width = 2*x + y - 3*r + 2*c4 + 15*thickness + 3*10 # lock
|
|
||||||
height = y + z + 8*thickness
|
|
||||||
|
|
||||||
Boxes.__init__(self, width, height, thickness=thickness)
|
|
||||||
self.edges["f"].settings.setValues(
|
|
||||||
self.thickness, finger=2, space=2, surroundingspaces=1)
|
|
||||||
|
|
||||||
s = FingerJointSettings(self.thickness, surroundingspaces=1)
|
|
||||||
g = FingerJointEdge(self, s)
|
|
||||||
g.char = "g"
|
|
||||||
self.addPart(g)
|
|
||||||
G = FingerJointEdgeCounterPart(self, s)
|
|
||||||
G.char = "G"
|
|
||||||
self.addPart(G)
|
|
||||||
|
|
||||||
def rectangleCorner(self, edge1=None, edge2=None):
|
def rectangleCorner(self, edge1=None, edge2=None):
|
||||||
edge1 = self.edges.get(edge1, edge1)
|
edge1 = self.edges.get(edge1, edge1)
|
||||||
edge2 = self.edges.get(edge2, edge2)
|
edge2 = self.edges.get(edge2, edge2)
|
||||||
|
@ -68,7 +59,7 @@ class FlexBox(Boxes):
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
|
|
||||||
def surroundingWall(self):
|
def surroundingWall(self):
|
||||||
x, y, z, r, d = self.x, self.y, self.z, self.r, self.d
|
x, y, z, r, d = self.x, self.y, self.z, self.radius, self.d
|
||||||
|
|
||||||
self.edges["F"](y-r, False)
|
self.edges["F"](y-r, False)
|
||||||
self.flexEdge(self.c4, z+2*self.thickness)
|
self.flexEdge(self.c4, z+2*self.thickness)
|
||||||
|
@ -93,7 +84,7 @@ class FlexBox(Boxes):
|
||||||
|
|
||||||
@restore
|
@restore
|
||||||
def lidSide(self):
|
def lidSide(self):
|
||||||
x, y, z, r, d, h = self.x, self.y, self.z, self.r, self.d, self.h
|
x, y, z, r, d, h = self.x, self.y, self.z, self.radius, self.d, self.h
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
r2 = r+t if r+t <=h+t else h+t
|
r2 = r+t if r+t <=h+t else h+t
|
||||||
self.moveTo(self.thickness, self.thickness)
|
self.moveTo(self.thickness, self.thickness)
|
||||||
|
@ -107,7 +98,28 @@ class FlexBox(Boxes):
|
||||||
self.edge(x+2*t)
|
self.edge(x+2*t)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, z, r, d, h = self.x, self.y, self.z, self.r, self.d, self.h
|
x, y, z, d, h = self.x, self.y, self.z, self.d, self.h
|
||||||
|
r = self.radius = self.radius or min(x, y)/2.0
|
||||||
|
thickness = self.thickness
|
||||||
|
|
||||||
|
self.c4 = c4 = math.pi * r * 0.5 * 0.95
|
||||||
|
self.latchsize = 8*thickness
|
||||||
|
|
||||||
|
width = 2*x + y - 2*r + c4 + 14*thickness + 3*h # lock
|
||||||
|
height = y + z + 8*thickness
|
||||||
|
|
||||||
|
self.open(width, height)
|
||||||
|
|
||||||
|
self.edges["f"].settings.setValues(
|
||||||
|
self.thickness, finger=2, space=2, surroundingspaces=1)
|
||||||
|
|
||||||
|
s = FingerJointSettings(self.thickness, surroundingspaces=1)
|
||||||
|
g = FingerJointEdge(self, s)
|
||||||
|
g.char = "g"
|
||||||
|
self.addPart(g)
|
||||||
|
G = FingerJointEdgeCounterPart(self, s)
|
||||||
|
G.char = "G"
|
||||||
|
self.addPart(G)
|
||||||
|
|
||||||
self.moveTo(2*self.thickness, self.thickness+2*d)
|
self.moveTo(2*self.thickness, self.thickness+2*d)
|
||||||
self.ctx.save()
|
self.ctx.save()
|
||||||
|
@ -134,5 +146,6 @@ class FlexBox(Boxes):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
b = FlexBox(100, 40, 100, r=20, h=10, thickness=4.0)
|
b = FlexBox() #100, 40, 100, r=20, h=10, thickness=4.0)
|
||||||
|
b.parseArgs()
|
||||||
b.render()
|
b.render()
|
||||||
|
|
20
flextest.py
20
flextest.py
|
@ -17,9 +17,17 @@
|
||||||
from boxes import *
|
from boxes import *
|
||||||
|
|
||||||
class FlexTest(Boxes):
|
class FlexTest(Boxes):
|
||||||
|
def __init__(self):
|
||||||
|
Boxes.__init__(self)
|
||||||
|
self.buildArgParser("x", "y")
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
x, y = self.x, self.y
|
||||||
|
self.open(x+60, y+20)
|
||||||
|
|
||||||
|
# (1.5, 3.0, 15.0) # line distance, connects, width
|
||||||
|
self.flexSettings = (2, 4.0, 16.0)
|
||||||
|
|
||||||
def render(self, x, y):
|
|
||||||
self.moveTo(5, 5)
|
self.moveTo(5, 5)
|
||||||
self.edge(10)
|
self.edge(10)
|
||||||
self.flexEdge(x, y)
|
self.flexEdge(x, y)
|
||||||
|
@ -34,10 +42,8 @@ class FlexTest(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
x = 40
|
if __name__ == '__main__':
|
||||||
y = 100
|
f = FlexTest()
|
||||||
f = FlexTest(x+30, y+10, thickness=5.0, burn=0.05)
|
f.parseArgs()
|
||||||
# (1.5, 3.0, 15.0) # line distance, connects, width
|
f.render()
|
||||||
f.flexSettings = (2, 4.0, 16.0)
|
|
||||||
f.render(x, y)
|
|
||||||
|
|
||||||
|
|
20
folder.py
20
folder.py
|
@ -19,16 +19,18 @@ import math
|
||||||
|
|
||||||
class Folder(Boxes):
|
class Folder(Boxes):
|
||||||
|
|
||||||
def __init__(self, x, y, h, r=0):
|
def __init__(self):
|
||||||
Boxes.__init__(self, width=2*x+3*h+20, height=y+20)
|
Boxes.__init__(self)
|
||||||
self.x = x
|
self.buildArgParser("x", "y", "h")
|
||||||
self.y = y
|
self.argparser.add_argument(
|
||||||
self.h = h
|
"-r", action="store", type=float, default=10.0,
|
||||||
self.r = r
|
help="radius of the corners")
|
||||||
|
self.argparser.set_defaults(h=20)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, r, h = self.x, self.y, self.r, self.h
|
x, y, r, h = self.x, self.y, self.r, self.h
|
||||||
c2 = math.pi * h
|
c2 = math.pi * h
|
||||||
|
self.open(width=2*x+3*h+20, height=y+20)
|
||||||
self.moveTo(r+self.thickness, self.thickness)
|
self.moveTo(r+self.thickness, self.thickness)
|
||||||
self.edge(x-r)
|
self.edge(x-r)
|
||||||
self.flexEdge(c2, y)
|
self.flexEdge(c2, y)
|
||||||
|
@ -43,5 +45,7 @@ class Folder(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
f = Folder(240, 350, 20, 15)
|
if __name__ == '__main__':
|
||||||
f.render()
|
f = Folder()
|
||||||
|
f.parseArgs()
|
||||||
|
f.render()
|
||||||
|
|
25
lamp.py
25
lamp.py
|
@ -57,13 +57,7 @@ class RoundedTriangle(Edge):
|
||||||
|
|
||||||
class Lamp(Boxes):
|
class Lamp(Boxes):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self, width=1000, height=1000,
|
Boxes.__init__(self)
|
||||||
thickness=5.0, burn=0.05)
|
|
||||||
self.fingerJointSettings = (5, 5) # XXX
|
|
||||||
|
|
||||||
s = RoundedTriangleSettings(self.thickness, angle=72, r_hole=2)
|
|
||||||
self.addPart(RoundedTriangle(self, s))
|
|
||||||
|
|
||||||
|
|
||||||
def side(self, y, h):
|
def side(self, y, h):
|
||||||
return
|
return
|
||||||
|
@ -82,6 +76,16 @@ class Lamp(Boxes):
|
||||||
y : width box
|
y : width box
|
||||||
h : height box
|
h : height box
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.open(width=1000, height=1000)
|
||||||
|
|
||||||
|
self.fingerJointSettings = (5, 5) # XXX
|
||||||
|
|
||||||
|
s = RoundedTriangleSettings(self.thickness, angle=72, r_hole=2)
|
||||||
|
self.addPart(RoundedTriangle(self, s))
|
||||||
|
|
||||||
|
self.flexSettings = (3, 5.0, 20.0)
|
||||||
|
|
||||||
self.fingerJointEdge.settings.setValues(self.thickness, finger=5, space=5, relative=False)
|
self.fingerJointEdge.settings.setValues(self.thickness, finger=5, space=5, relative=False)
|
||||||
d = 2*(r+w)
|
d = 2*(r+w)
|
||||||
|
|
||||||
|
@ -112,6 +116,7 @@ class Lamp(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
l = Lamp()
|
if __name__ == '__main__':
|
||||||
l.flexSettings = (3, 5.0, 20.0)
|
l = Lamp()
|
||||||
l.render(r=4*25.4, w=20, x=270, y=150, h=100)
|
l.parseArgs()
|
||||||
|
l.render(r=4*25.4, w=20, x=270, y=150, h=100)
|
||||||
|
|
|
@ -17,19 +17,18 @@
|
||||||
from boxes import *
|
from boxes import *
|
||||||
|
|
||||||
class Box(Boxes):
|
class Box(Boxes):
|
||||||
def __init__(self, x, y, h, h2, thickness=4.0):
|
def __init__(self):
|
||||||
self.x, self.y, self.h, self.h2 = x, y, h, h2
|
Boxes.__init__(self)
|
||||||
Boxes.__init__(self, width=x+y+8*thickness, height=x+h+h2+4*thickness,
|
self.buildArgParser("x", "y", "h", "hi")
|
||||||
thickness=thickness)
|
|
||||||
|
|
||||||
def side(self, w, h, h2):
|
def side(self, w, h, hi):
|
||||||
r = min(h-h2, w) / 2.0
|
r = min(h-hi, w) / 2.0
|
||||||
if (h-h2) > w:
|
if (h-hi) > w:
|
||||||
r = w / 2.0
|
r = w / 2.0
|
||||||
lx = 0
|
lx = 0
|
||||||
ly = (h-h2) - w
|
ly = (h-hi) - w
|
||||||
else:
|
else:
|
||||||
r = (h - h2) / 2.0
|
r = (h - hi) / 2.0
|
||||||
lx = (w - 2*r) / 2.0
|
lx = (w - 2*r) / 2.0
|
||||||
ly = 0
|
ly = 0
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ class Box(Boxes):
|
||||||
self.edge(e_w)
|
self.edge(e_w)
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
self.edge(e_w)
|
self.edge(e_w)
|
||||||
self.edges["F"](h2)
|
self.edges["F"](hi)
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
self.edge(e_w)
|
self.edge(e_w)
|
||||||
self.edge(lx)
|
self.edge(lx)
|
||||||
|
@ -56,23 +55,29 @@ class Box(Boxes):
|
||||||
|
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, h, h2 = self.x, self.y, self.h, self.h2
|
x, y, h, = self.x, self.y, self.h
|
||||||
|
self.hi = hi = self.hi or (h / 2.0)
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
|
||||||
|
self.open(width=x+y+8*t, height=x+h+hi+4*t)
|
||||||
|
|
||||||
|
self.edges["f"].settings.setValues(self.thickness, space=2, finger=2)
|
||||||
|
|
||||||
self.ctx.save()
|
self.ctx.save()
|
||||||
self.rectangularWall(x, h, "Ffef", move="up")
|
self.rectangularWall(x, h, "Ffef", move="up")
|
||||||
self.rectangularWall(x, h2, "Ffef", move="up")
|
self.rectangularWall(x, hi, "Ffef", move="up")
|
||||||
|
|
||||||
self.rectangularWall(y, x, "ffff")
|
self.rectangularWall(y, x, "ffff")
|
||||||
self.ctx.restore()
|
self.ctx.restore()
|
||||||
|
|
||||||
self.rectangularWall(x, h, "Ffef", move="right only")
|
self.rectangularWall(x, h, "Ffef", move="right only")
|
||||||
self.side(y, h, h2)
|
self.side(y, h, hi)
|
||||||
self.moveTo(y+15, h+h2+15, 180)
|
self.moveTo(y+15, h+hi+15, 180)
|
||||||
self.side(y, h, h2)
|
self.side(y, h, hi)
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
b = Box(80, 235, 300, 150)
|
if __name__ == '__main__':
|
||||||
b.edges["f"].settings.setValues(b.thickness, space=2, finger=2)
|
b = Box()
|
||||||
b.render()
|
b.parseArgs()
|
||||||
|
b.render()
|
||||||
|
|
|
@ -20,8 +20,7 @@ class Printer(Boxes):
|
||||||
|
|
||||||
"""Work in progress"""
|
"""Work in progress"""
|
||||||
def __init__(self, r=250, h=400, d_c=100):
|
def __init__(self, r=250, h=400, d_c=100):
|
||||||
Boxes.__init__(self, 650, 600, thickness=5.0, burn=0.05)
|
Boxes.__init__(self)
|
||||||
self.edges["f"].settings.setValues(self.thickness, surroundingspaces=0)
|
|
||||||
self.r = r
|
self.r = r
|
||||||
self.h = h
|
self.h = h
|
||||||
self.d_c = d_c
|
self.d_c = d_c
|
||||||
|
@ -122,6 +121,8 @@ class Printer(Boxes):
|
||||||
self.move(overallwidth, overallheight, move)
|
self.move(overallwidth, overallheight, move)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
|
self.open(650, 600)
|
||||||
|
self.edges["f"].settings.setValues(self.thickness, surroundingspaces=0)
|
||||||
self.ctx.save()
|
self.ctx.save()
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
# motor mounts
|
# motor mounts
|
||||||
|
@ -175,4 +176,5 @@ class Printer(Boxes):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
p = Printer()
|
p = Printer()
|
||||||
|
p.parseArgs()
|
||||||
p.render()
|
p.render()
|
||||||
|
|
|
@ -66,6 +66,7 @@ class Silverware(Boxes):
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
def render(self, x, y, h, r):
|
def render(self, x, y, h, r):
|
||||||
|
self.open(750, 450)
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
b = self.burn
|
b = self.burn
|
||||||
|
|
||||||
|
@ -81,8 +82,7 @@ class Silverware(Boxes):
|
||||||
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
b = Silverware(750, 350, thickness=5.0, burn=0.05)
|
if __name__ == '__main__':
|
||||||
b.render(250, 250/1.618, 120, 30)
|
b = Silverware()
|
||||||
#b = Silverware(300, 300, thickness=3.0, burn=0.05)
|
b.parseArgs()
|
||||||
#b.fingerJointSettings = (b.thickness, b.thickness)
|
b.render(250, 250/1.618, 120, 30)
|
||||||
#b.render(60, 60/1.618, 40, 10)
|
|
||||||
|
|
|
@ -17,48 +17,33 @@
|
||||||
from boxes import *
|
from boxes import *
|
||||||
|
|
||||||
class TrayInsert(Boxes):
|
class TrayInsert(Boxes):
|
||||||
def __init__(self, x, y, h, **kw):
|
def __init__(self):
|
||||||
self.x, self.y, self.h = x, y, h
|
Boxes.__init__(self)
|
||||||
t = kw.get("thickness", 4.0)
|
self.buildArgParser("sx", "sy", "h")
|
||||||
Boxes.__init__(self, width=max(sum(x)+len(x)*t, sum(y)+len(y)*t)+2*t,
|
|
||||||
height=(len(x)+len(y)-2)*(h+t)+2*t, **kw)
|
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x = sum(self.x) + self.thickness * (len(self.x)-1)
|
x = sum(self.sx) + self.thickness * (len(self.sx)-1)
|
||||||
y = sum(self.y) + self.thickness * (len(self.y)-1)
|
y = sum(self.sy) + self.thickness * (len(self.sy)-1)
|
||||||
h = self.h
|
h = self.h
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
|
||||||
|
self.open(width=max(x, y) + 4*t,
|
||||||
|
height=(len(self.sx)+len(self.sy)-2)*(h+t)+2*t)
|
||||||
self.moveTo(t, t)
|
self.moveTo(t, t)
|
||||||
|
|
||||||
# Inner walls
|
# Inner walls
|
||||||
for i in range(len(self.x)-1):
|
for i in range(len(self.sx)-1):
|
||||||
e = [SlottedEdge(self, self.y, slots=0.5*h), "e", "e", "e"]
|
e = [SlottedEdge(self, self.sy, slots=0.5*h), "e", "e", "e"]
|
||||||
self.rectangularWall(y, h, e,
|
self.rectangularWall(y, h, e,
|
||||||
move="up")
|
move="up")
|
||||||
for i in range(len(self.y)-1):
|
for i in range(len(self.sy)-1):
|
||||||
e = ["e", "e",
|
e = ["e", "e",
|
||||||
SlottedEdge(self, self.x[::-1], "e", slots=0.5*h), "e"]
|
SlottedEdge(self, self.sx[::-1], "e", slots=0.5*h), "e"]
|
||||||
self.rectangularWall(x, h, e,
|
self.rectangularWall(x, h, e,
|
||||||
move="up")
|
move="up")
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
# Calculate equidistant section
|
b = TrayInsert()
|
||||||
x = 260 # width
|
b.parseArgs()
|
||||||
nx = 3
|
b.render()
|
||||||
y = 300 # depth
|
|
||||||
ny = 4
|
|
||||||
thickness=4.0
|
|
||||||
dx = (x+thickness)/nx-thickness
|
|
||||||
dy = (y+thickness)/ny-thickness
|
|
||||||
|
|
||||||
sx = [dx] * nx
|
|
||||||
sy = [dy] * ny
|
|
||||||
|
|
||||||
# Or give sections by hand
|
|
||||||
#sx = [80, 100, 80]
|
|
||||||
#sy = [80, 120, 200]
|
|
||||||
|
|
||||||
b = TrayInsert(sx, sy, 80, thickness=thickness, burn=0.1)
|
|
||||||
b.render()
|
|
||||||
|
|
61
typetray.py
61
typetray.py
|
@ -17,45 +17,44 @@
|
||||||
from boxes import *
|
from boxes import *
|
||||||
|
|
||||||
class TypeTray(Boxes):
|
class TypeTray(Boxes):
|
||||||
def __init__(self, x, y, h, hi=None, **kw):
|
def __init__(self):
|
||||||
self.x, self.y, self.h = x, y, h
|
Boxes.__init__(self)
|
||||||
self.hi = hi or h
|
self.buildArgParser("sx", "sy", "h", "hi")
|
||||||
Boxes.__init__(self, width=sum(x)+sum(y)+70, height=sum(y)+1*h+50, **kw)
|
|
||||||
|
|
||||||
def xSlots(self):
|
def xSlots(self):
|
||||||
posx = -0.5 * self.thickness
|
posx = -0.5 * self.thickness
|
||||||
for x in self.x[:-1]:
|
for x in self.sx[:-1]:
|
||||||
posx += x + self.thickness
|
posx += x + self.thickness
|
||||||
posy = 0
|
posy = 0
|
||||||
for y in self.y:
|
for y in self.sy:
|
||||||
self.fingerHolesAt(posx, posy, y)
|
self.fingerHolesAt(posx, posy, y)
|
||||||
posy += y + self.thickness
|
posy += y + self.thickness
|
||||||
|
|
||||||
def ySlots(self):
|
def ySlots(self):
|
||||||
posy = -0.5 * self.thickness
|
posy = -0.5 * self.thickness
|
||||||
for y in self.y[:-1]:
|
for y in self.sy[:-1]:
|
||||||
posy += y + self.thickness
|
posy += y + self.thickness
|
||||||
posx = 0
|
posx = 0
|
||||||
for x in self.x:
|
for x in self.sx:
|
||||||
self.fingerHolesAt(posy, posx, x)
|
self.fingerHolesAt(posy, posx, x)
|
||||||
posx += x + self.thickness
|
posx += x + self.thickness
|
||||||
|
|
||||||
def xHoles(self):
|
def xHoles(self):
|
||||||
posx = -0.5 * self.thickness
|
posx = -0.5 * self.thickness
|
||||||
for x in self.x[:-1]:
|
for x in self.sx[:-1]:
|
||||||
posx += x + self.thickness
|
posx += x + self.thickness
|
||||||
self.fingerHolesAt(posx, 0, self.hi)
|
self.fingerHolesAt(posx, 0, self.hi)
|
||||||
|
|
||||||
def yHoles(self):
|
def yHoles(self):
|
||||||
posy = -0.5 * self.thickness
|
posy = -0.5 * self.thickness
|
||||||
for y in self.y[:-1]:
|
for y in self.sy[:-1]:
|
||||||
posy += y + self.thickness
|
posy += y + self.thickness
|
||||||
self.fingerHolesAt(posy, 0, self.hi)
|
self.fingerHolesAt(posy, 0, self.hi)
|
||||||
|
|
||||||
def fingerHole(self):
|
def fingerHole(self):
|
||||||
dx = 50
|
dx = 50
|
||||||
dy = 30
|
dy = 30
|
||||||
x = sum(self.x) + self.thickness * (len(self.x)-1)
|
x = sum(self.sx) + self.thickness * (len(self.sx)-1)
|
||||||
self.moveTo(0.5*(x-dx), 5)
|
self.moveTo(0.5*(x-dx), 5)
|
||||||
self.edge(dx)
|
self.edge(dx)
|
||||||
self.corner(180, 0.5*dy)
|
self.corner(180, 0.5*dy)
|
||||||
|
@ -65,12 +64,16 @@ class TypeTray(Boxes):
|
||||||
#self.hole(0.5*x+30, 15, 10)
|
#self.hole(0.5*x+30, 15, 10)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x = sum(self.x) + self.thickness * (len(self.x)-1)
|
x = sum(self.sx) + self.thickness * (len(self.sx)-1)
|
||||||
y = sum(self.y) + self.thickness * (len(self.y)-1)
|
y = sum(self.sy) + self.thickness * (len(self.sy)-1)
|
||||||
h = self.h
|
h = self.h
|
||||||
hi = self.hi
|
hi = self.hi = self.hi or h
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
|
||||||
|
self.open(width=x+y+10*t, height=y+(len(self.sx)+len(self.sy))*h+50)
|
||||||
|
self.edges["f"].settings.setValues(self.thickness, space=3, finger=3,
|
||||||
|
surroundingspaces=0.5)
|
||||||
|
|
||||||
self.moveTo(t, t)
|
self.moveTo(t, t)
|
||||||
# outer walls
|
# outer walls
|
||||||
self.rectangularWall(x, h, "Ffef", callback=[
|
self.rectangularWall(x, h, "Ffef", callback=[
|
||||||
|
@ -87,30 +90,18 @@ class TypeTray(Boxes):
|
||||||
callback=[self.xSlots, self.ySlots],
|
callback=[self.xSlots, self.ySlots],
|
||||||
move="right")
|
move="right")
|
||||||
# Inner walls
|
# Inner walls
|
||||||
for i in range(len(self.x)-1):
|
for i in range(len(self.sx)-1):
|
||||||
e = [SlottedEdge(self, self.y, "f", slots=0.5*hi), "f", "e", "f"]
|
e = [SlottedEdge(self, self.sy, "f", slots=0.5*hi), "f", "e", "f"]
|
||||||
self.rectangularWall(y, hi, e,
|
self.rectangularWall(y, hi, e,
|
||||||
move="up")
|
move="up")
|
||||||
for i in range(len(self.y)-1):
|
for i in range(len(self.sy)-1):
|
||||||
e = [SlottedEdge(self, self.x, "f"), "f",
|
e = [SlottedEdge(self, self.sx, "f"), "f",
|
||||||
SlottedEdge(self, self.x[::-1], "e", slots=0.5*hi), "f"]
|
SlottedEdge(self, self.sx[::-1], "e", slots=0.5*hi), "f"]
|
||||||
self.rectangularWall(x, hi, e,
|
self.rectangularWall(x, hi, e,
|
||||||
move="up")
|
move="up")
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
x = 260 # outer width
|
if __name__ == '__main__':
|
||||||
nx = 3
|
b = TypeTray()
|
||||||
y = 300 # outer depth
|
b.parseArgs()
|
||||||
ny = 4
|
b.render()
|
||||||
thickness=4.0
|
|
||||||
|
|
||||||
dx = (x-thickness)/nx-thickness
|
|
||||||
dy = (y-thickness)/ny-thickness
|
|
||||||
sx = [dx] * nx
|
|
||||||
sy = [dy] * ny
|
|
||||||
#sy = [120, 300-3*thickness-120]
|
|
||||||
|
|
||||||
b = TypeTray(sx, sy, 78-thickness, 40, thickness=thickness, burn=0.1)
|
|
||||||
b.edges["f"].settings.setValues(b.thickness, space=3, finger=3,
|
|
||||||
surroundingspaces=0.5)
|
|
||||||
b.render()
|
|
||||||
|
|
Loading…
Reference in New Issue