Move silverware box into an own file
This commit is contained in:
parent
0f1a5a540c
commit
dc02a0d86b
146
boxes.py
146
boxes.py
|
@ -210,6 +210,34 @@ class Boxes:
|
|||
self.ctx.line_to(x, 0)
|
||||
self.ctx.translate(*self.ctx.get_current_point())
|
||||
|
||||
def handle(self, x, h, hl, r=20):
|
||||
"""Creates and Edge with a handle"""
|
||||
d = (x-hl-2*r)/2.0
|
||||
if d < 0:
|
||||
print "Handle too wide"
|
||||
|
||||
self.ctx.save()
|
||||
|
||||
# Hole
|
||||
self.moveTo(d+20+r, 0)
|
||||
self.edge(hl-2*r)
|
||||
self.corner(-90, r)
|
||||
self.edge(h-20-2*r)
|
||||
self.corner(-90, r)
|
||||
self.edge(hl-2*r)
|
||||
self.corner(-90, r)
|
||||
self.edge(h-20-2*r)
|
||||
self.corner(-90, r)
|
||||
|
||||
self.ctx.restore()
|
||||
self.moveTo(0,0)
|
||||
|
||||
self.curveTo(d, 0, d, 0, d, -h+r)
|
||||
self.curveTo(r, 0, r, 0, r, r)
|
||||
self.edge(hl)
|
||||
self.curveTo(r, 0, r, 0, r, r)
|
||||
self.curveTo(h-r, 0, h-r, 0, h-r, -d)
|
||||
|
||||
### Navigation
|
||||
|
||||
def moveTo(self, x, y, degrees=0):
|
||||
|
@ -352,111 +380,6 @@ class Boxes:
|
|||
self.edge(bottomwidth)
|
||||
self.corner(90)
|
||||
|
||||
####################################################################
|
||||
### Parts
|
||||
####################################################################
|
||||
|
||||
def basePlate(self, x=100, y=100, r=0):
|
||||
self.ctx.save()
|
||||
self.moveTo(r, 0)
|
||||
|
||||
# two walls
|
||||
self.fingerHolesAt(x/3.0-r, 0, 0.5*y-self.thickness)
|
||||
self.fingerHolesAt(x*2/3.0-r, 0, 0.5*y-self.thickness)
|
||||
|
||||
self.fingerJoint(0.5*x-r)
|
||||
self.fingerJoint(0.5*x-r)
|
||||
|
||||
self.corner(90, r)
|
||||
|
||||
# Middle wall
|
||||
self.fingerHolesAt(y/2.0-r, 0, x)
|
||||
|
||||
self.fingerJoint(y-2*r)
|
||||
self.corner(90, r)
|
||||
|
||||
# single wall
|
||||
self.fingerHolesAt(x/2.0-r, 0, 0.5*y-self.thickness)
|
||||
|
||||
self.fingerJoint(x-2*r)
|
||||
|
||||
self.corner(90, r)
|
||||
self.fingerJoint(y-2*r)
|
||||
self.corner(90, r)
|
||||
|
||||
self.ctx.restore()
|
||||
|
||||
def wall(self, x=100, y=100, h=100, r=0):
|
||||
self.surroundingWall(x,y,r,h, bottom='finger', callback={
|
||||
0 : lambda: self.fingerHolesAt(x/6.0, 0, h),
|
||||
4 : lambda: self.fingerHolesAt(x/3.0-r, 0, h),
|
||||
1 : lambda: self.fingerHolesAt(y/2.0-r, 0, h),
|
||||
3 : lambda: self.fingerHolesAt(y/2.0-r, 0, h),
|
||||
2 : lambda: self.fingerHolesAt(x/2.0-r, 0, h),
|
||||
})
|
||||
|
||||
def smallWall(self, y, h):
|
||||
l = 0.5*y - self.thickness
|
||||
|
||||
self.ctx.save()
|
||||
self.moveTo(10, 0)
|
||||
|
||||
self.fingerJoint(l)
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
self.edge(l)
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
|
||||
self.ctx.restore()
|
||||
|
||||
|
||||
def handle(self, x, h, hl, r=20):
|
||||
d = (x-hl-2*r)/2.0
|
||||
if d < 0:
|
||||
print "Handle too wide"
|
||||
|
||||
self.ctx.save()
|
||||
|
||||
# Hole
|
||||
self.moveTo(d+20+r, 0)
|
||||
self.edge(hl-2*r)
|
||||
self.corner(-90, r)
|
||||
self.edge(h-20-2*r)
|
||||
self.corner(-90, r)
|
||||
self.edge(hl-2*r)
|
||||
self.corner(-90, r)
|
||||
self.edge(h-20-2*r)
|
||||
self.corner(-90, r)
|
||||
|
||||
self.ctx.restore()
|
||||
self.moveTo(0,0)
|
||||
|
||||
self.curveTo(d, 0, d, 0, d, -h+r)
|
||||
self.curveTo(r, 0, r, 0, r, r)
|
||||
self.edge(hl)
|
||||
self.curveTo(r, 0, r, 0, r, r)
|
||||
self.curveTo(h-r, 0, h-r, 0, h-r, -d)
|
||||
|
||||
def centerWall(self, x, h):
|
||||
self.ctx.save()
|
||||
|
||||
for i in range(2, 5):
|
||||
self.fingerHolesAt(i*x/6.0, 0, h-20)
|
||||
|
||||
self.fingerJoint(x)
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
|
||||
self.handle(x, 150, 120)
|
||||
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
self.ctx.restore()
|
||||
|
||||
##################################################
|
||||
### main
|
||||
|
@ -465,18 +388,7 @@ class Boxes:
|
|||
def render(self, x, y, h, r):
|
||||
self.ctx.save()
|
||||
|
||||
self.moveTo(10, 10)
|
||||
self.wall(x, y, h+self.thickness+5, r)
|
||||
self.moveTo(0, h+20)
|
||||
self.centerWall(x,h)
|
||||
self.moveTo(x+20, 0)
|
||||
|
||||
for i in range(3):
|
||||
self.smallWall(y, h)
|
||||
self.moveTo(y/2.0+20, 0)
|
||||
|
||||
self.moveTo(-1.5*y-80, h)
|
||||
self.basePlate(x, y, r)
|
||||
# XXX add parts
|
||||
|
||||
self.ctx.restore()
|
||||
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from boxes import Boxes
|
||||
|
||||
class Silverware(Boxes):
|
||||
####################################################################
|
||||
### Parts
|
||||
####################################################################
|
||||
|
||||
def basePlate(self, x=100, y=100, r=0):
|
||||
self.ctx.save()
|
||||
self.moveTo(r, 0)
|
||||
|
||||
# two walls
|
||||
self.fingerHolesAt(x/3.0-r, 0, 0.5*y-self.thickness)
|
||||
self.fingerHolesAt(x*2/3.0-r, 0, 0.5*y-self.thickness)
|
||||
|
||||
self.fingerJoint(0.5*x-r)
|
||||
self.fingerJoint(0.5*x-r)
|
||||
|
||||
self.corner(90, r)
|
||||
|
||||
# Middle wall
|
||||
self.fingerHolesAt(y/2.0-r, 0, x)
|
||||
|
||||
self.fingerJoint(y-2*r)
|
||||
self.corner(90, r)
|
||||
|
||||
# single wall
|
||||
self.fingerHolesAt(x/2.0-r, 0, 0.5*y-self.thickness)
|
||||
|
||||
self.fingerJoint(x-2*r)
|
||||
|
||||
self.corner(90, r)
|
||||
self.fingerJoint(y-2*r)
|
||||
self.corner(90, r)
|
||||
|
||||
self.ctx.restore()
|
||||
|
||||
def wall(self, x=100, y=100, h=100, r=0):
|
||||
self.surroundingWall(x,y,r,h, bottom='finger', callback={
|
||||
0 : lambda: self.fingerHolesAt(x/6.0, 0, h),
|
||||
4 : lambda: self.fingerHolesAt(x/3.0-r, 0, h),
|
||||
1 : lambda: self.fingerHolesAt(y/2.0-r, 0, h),
|
||||
3 : lambda: self.fingerHolesAt(y/2.0-r, 0, h),
|
||||
2 : lambda: self.fingerHolesAt(x/2.0-r, 0, h),
|
||||
})
|
||||
|
||||
def smallWall(self, y, h):
|
||||
l = 0.5*y - self.thickness
|
||||
|
||||
self.ctx.save()
|
||||
self.moveTo(10, 0)
|
||||
|
||||
self.fingerJoint(l)
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
self.edge(l)
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
|
||||
self.ctx.restore()
|
||||
|
||||
def centerWall(self, x, h):
|
||||
self.ctx.save()
|
||||
|
||||
for i in range(2, 5):
|
||||
self.fingerHolesAt(i*x/6.0, 0, h-20)
|
||||
|
||||
self.fingerJoint(x)
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
|
||||
self.handle(x, 150, 120)
|
||||
|
||||
self.corner(90)
|
||||
self.fingerJoint(h-20)
|
||||
self.corner(90)
|
||||
self.ctx.restore()
|
||||
|
||||
##################################################
|
||||
### main
|
||||
##################################################
|
||||
|
||||
def render(self, x, y, h, r):
|
||||
self.ctx.save()
|
||||
|
||||
self.moveTo(10, 10)
|
||||
self.wall(x, y, h+self.thickness+5, r)
|
||||
self.moveTo(0, h+20)
|
||||
self.centerWall(x,h)
|
||||
self.moveTo(x+20, 0)
|
||||
|
||||
for i in range(3):
|
||||
self.smallWall(y, h)
|
||||
self.moveTo(y/2.0+20, 0)
|
||||
|
||||
self.moveTo(-1.5*y-80, h)
|
||||
self.basePlate(x, y, r)
|
||||
|
||||
self.ctx.restore()
|
||||
|
||||
self.ctx.stroke()
|
||||
self.surface.flush()
|
||||
|
||||
b = Silverware(900, 700)
|
||||
b.render(250, 250/1.618, 120, 30)
|
Loading…
Reference in New Issue