ShutterBox: Add style with two rounded corners
Move generator to FlexBox category
This commit is contained in:
parent
879b3149bb
commit
2df63b6ec8
|
@ -19,11 +19,11 @@ from boxes import *
|
||||||
class ShutterBox(Boxes):
|
class ShutterBox(Boxes):
|
||||||
"""Box with a rolling shutter made of flex"""
|
"""Box with a rolling shutter made of flex"""
|
||||||
|
|
||||||
ui_group = "Box"
|
ui_group = "FlexBox"
|
||||||
|
|
||||||
description = "Beware of the rolling shutter effect! Use wax on sliding surfaces."
|
description = "Beware of the rolling shutter effect! Use wax on sliding surfaces."
|
||||||
|
|
||||||
def side(self, l, h, r, move=None):
|
def side(self, l, h, r, style, move=None):
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
|
|
||||||
if self.move(l+2*t, h+2*t, move, True):
|
if self.move(l+2*t, h+2*t, move, True):
|
||||||
|
@ -38,7 +38,20 @@ class ShutterBox(Boxes):
|
||||||
ls = 2*math.sin(math.radians(a/2)) * (r-2.5*t)
|
ls = 2*math.sin(math.radians(a/2)) * (r-2.5*t)
|
||||||
|
|
||||||
#self.hole(l-r, r, r-2.5*t)
|
#self.hole(l-r, r, r-2.5*t)
|
||||||
self.fingerHolesAt(0, 2*t, l-r, 0)
|
if style == "double":
|
||||||
|
#self.hole(r, r, r-2.5*t)
|
||||||
|
self.ctx.save()
|
||||||
|
self.fingerHolesAt(r, 2*t, l-2*r, 0)
|
||||||
|
self.moveTo(r, 2.5*t, 180 - a/2)
|
||||||
|
for i in range(n):
|
||||||
|
self.fingerHolesAt(0, 0.5*t, ls, 0)
|
||||||
|
self.moveTo(ls, 0, -a)
|
||||||
|
if h - 2*r > 2*t:
|
||||||
|
self.moveTo(0, 0, a/2)
|
||||||
|
self.fingerHolesAt(0, 0.5*t, h - 2*r, 0)
|
||||||
|
self.ctx.restore()
|
||||||
|
else:
|
||||||
|
self.fingerHolesAt(0, 2*t, l-r, 0)
|
||||||
self.moveTo(l-r, 2.5*t, a/2)
|
self.moveTo(l-r, 2.5*t, a/2)
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
self.fingerHolesAt(0, -0.5*t, ls, 0)
|
self.fingerHolesAt(0, -0.5*t, ls, 0)
|
||||||
|
@ -51,8 +64,13 @@ class ShutterBox(Boxes):
|
||||||
self.edges["f"](l)
|
self.edges["f"](l)
|
||||||
self.corner(90)
|
self.corner(90)
|
||||||
self.edges["f"](h-r)
|
self.edges["f"](h-r)
|
||||||
self.polyline(0, -90, t, 90, 0, (90, r+t), l-r, 90, t)
|
self.polyline(0, -90, t, 90, 0, (90, r+t))
|
||||||
self.edges["f"](h)
|
if style == "single":
|
||||||
|
self.polyline(l-r, 90, t)
|
||||||
|
self.edges["f"](h)
|
||||||
|
else:
|
||||||
|
self.polyline(l-2*r, (90, r+t), 0, 90, t, -90)
|
||||||
|
self.edges["f"](h-r)
|
||||||
|
|
||||||
self.move(l+2*t, h+2*t, move)
|
self.move(l+2*t, h+2*t, move)
|
||||||
|
|
||||||
|
@ -84,6 +102,26 @@ class ShutterBox(Boxes):
|
||||||
|
|
||||||
self.move(tw, th, move)
|
self.move(tw, th, move)
|
||||||
|
|
||||||
|
def rails2(self, l, r, move=None):
|
||||||
|
t = self.thickness
|
||||||
|
s = self.spacing
|
||||||
|
tw, th = l+2.5*t+3*s, 2*r+t
|
||||||
|
|
||||||
|
if self.move(tw, th, move, True):
|
||||||
|
return
|
||||||
|
|
||||||
|
self.moveTo(r+t, 0)
|
||||||
|
for i in range(2):
|
||||||
|
self.polyline(l-2*r, (90, r+t), 0, 90, t, 90, 0, (-90, r), l-2*r,
|
||||||
|
(-90, r), 0, 90, t, 90, 0, (90, r+t))
|
||||||
|
self.moveTo(0, 1.5*t)
|
||||||
|
self.polyline(l-2*r, (90, r-1.5*t), 0, 90, t, 90, 0, (-90, r-2.5*t), l-2*r,
|
||||||
|
(-90, r-2.5*t), 0, 90, t, 90, 0, (90, r-1.5*t))
|
||||||
|
self.moveTo(0, r)
|
||||||
|
|
||||||
|
self.move(tw, th, move)
|
||||||
|
|
||||||
|
|
||||||
def door(self, l, h, move=None):
|
def door(self, l, h, move=None):
|
||||||
t = self.thickness
|
t = self.thickness
|
||||||
if self.move(l, h, move, True):
|
if self.move(l, h, move, True):
|
||||||
|
@ -97,17 +135,22 @@ class ShutterBox(Boxes):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Boxes.__init__(self)
|
Boxes.__init__(self)
|
||||||
|
|
||||||
self.addSettingsArgs(edges.FingerJointSettings)
|
self.addSettingsArgs(edges.FingerJointSettings, surroundingspaces=0.5)
|
||||||
self.addSettingsArgs(edges.FlexSettings, distance=.75, connection=2.)
|
self.addSettingsArgs(edges.FlexSettings, distance=.75, connection=2.)
|
||||||
|
|
||||||
self.buildArgParser(x=100, y=100, h=100)
|
self.buildArgParser(x=150, y=100, h=100)
|
||||||
self.argparser.add_argument(
|
self.argparser.add_argument(
|
||||||
"--radius", action="store", type=float, default=0.0,
|
"--radius", action="store", type=float, default=40.0,
|
||||||
help="radius of the corners")
|
help="radius of the corners")
|
||||||
|
self.argparser.add_argument(
|
||||||
|
"--style", action="store", type=str, default="single",
|
||||||
|
choices=["single", "double"],
|
||||||
|
help="Number of rounded top corners")
|
||||||
|
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
x, y, h, r = self.x, self.y, self.h, self.radius
|
x, y, h, r = self.x, self.y, self.h, self.radius
|
||||||
|
style = self.style
|
||||||
|
|
||||||
self.n = n = 3
|
self.n = n = 3
|
||||||
|
|
||||||
|
@ -119,18 +162,32 @@ class ShutterBox(Boxes):
|
||||||
# Initialize canvas
|
# Initialize canvas
|
||||||
self.open()
|
self.open()
|
||||||
self.ctx.save()
|
self.ctx.save()
|
||||||
self.side(x, h, r, move="right")
|
self.side(x, h, r, style, move="right")
|
||||||
self.side(x, h, r, move="right")
|
self.side(x, h, r, style, move="right")
|
||||||
self.rectangularWall(y, h, "fFEF", move="right")
|
if style == "single":
|
||||||
|
self.rectangularWall(y, h, "fFEF", move="right")
|
||||||
|
else:
|
||||||
|
self.rectangularWall(y, h-r, "fFeF", move="right")
|
||||||
self.rectangularWall(y, h-r, "fFeF", move="right")
|
self.rectangularWall(y, h-r, "fFeF", move="right")
|
||||||
|
|
||||||
|
if style == "double":
|
||||||
|
self.cornerRadius(r, two=True, move="right")
|
||||||
|
|
||||||
self.cornerRadius(r, two=True, move="right")
|
self.cornerRadius(r, two=True, move="right")
|
||||||
self.rails(x, r, move="right")
|
if style == "single":
|
||||||
|
self.rails(x, r, move="right")
|
||||||
|
else:
|
||||||
|
self.rails2(x, r, move="right")
|
||||||
|
|
||||||
self.ctx.restore()
|
self.ctx.restore()
|
||||||
self.side(x, h, r, move="up only")
|
self.side(x, h, r, style, move="up only")
|
||||||
|
|
||||||
self.rectangularWall(x, y, "FFFF", move="right")
|
self.rectangularWall(x, y, "FFFF", move="right")
|
||||||
self.door(x-r+0.5*math.pi*r + 3*t, y-0.2*t, move="right")
|
|
||||||
|
if style == "single":
|
||||||
|
self.door(x-r+0.5*math.pi*r + 3*t, y-0.2*t, move="right")
|
||||||
|
else:
|
||||||
|
self.door(x-2*r+math.pi*r + 3*t, y-0.2*t, move="right")
|
||||||
|
|
||||||
self.rectangularWall(2*t, y-2.2*t, edges="eeef", move="right")
|
self.rectangularWall(2*t, y-2.2*t, edges="eeef", move="right")
|
||||||
|
|
||||||
|
@ -141,7 +198,22 @@ class ShutterBox(Boxes):
|
||||||
edges.FingerJointSettings(t, angle=a).edgeObjects(self, chars="aA")
|
edges.FingerJointSettings(t, angle=a).edgeObjects(self, chars="aA")
|
||||||
edges.FingerJointSettings(t, angle=a/2).edgeObjects(self, chars="bB")
|
edges.FingerJointSettings(t, angle=a/2).edgeObjects(self, chars="bB")
|
||||||
|
|
||||||
self.rectangularWall(x-r, y, "fbfe", move="right")
|
|
||||||
|
if style == "double":
|
||||||
|
if h - 2*r > 2*t:
|
||||||
|
self.rectangularWall(h - 2*r, y, "fBfe", move="right")
|
||||||
|
self.rectangularWall(ls, y, "fAfb", move="right")
|
||||||
|
else:
|
||||||
|
self.rectangularWall(ls, y, "fAfe", move="right")
|
||||||
|
|
||||||
|
for i in range(n-2):
|
||||||
|
self.rectangularWall(ls, y, "fAfa", move="right")
|
||||||
|
|
||||||
|
self.rectangularWall(ls, y, "fBfa", move="right")
|
||||||
|
|
||||||
|
self.rectangularWall(x-2*r, y, "fbfb", move="right")
|
||||||
|
else:
|
||||||
|
self.rectangularWall(x-r, y, "fbfe", move="right")
|
||||||
|
|
||||||
self.rectangularWall(ls, y, "fafB", move="right")
|
self.rectangularWall(ls, y, "fafB", move="right")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue