diff --git a/boxes/generators/regularstarbox.py b/boxes/generators/regularstarbox.py new file mode 100644 index 0000000..60e1d91 --- /dev/null +++ b/boxes/generators/regularstarbox.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +# Copyright (C) 2013-2014 Florian Festi +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from boxes import * +import copy + +class SlotEdge(edges.Edge): + + def __call__(self, length, **kw): + t, n = self.settings.thickness, self.settings.n + r, h = self.settings.radius, self.settings.h + sh = self.settings.sh # distance side to center + + li = 2 * sh * math.tan(math.radians(90/n)) # side inner 2x polygone + ls2 = t / math.tan(math.radians(180/n)) + ls1 = t / math.cos(math.radians(90-(180/n))) + + lo = (length-li-2*ls1)/2 + + li = li - 2*ls2 # correct for overlap of wall + + d = h/2 + + if li > 0: + poly = [lo-1, (90, 1), d+t-1, -90, ls1+ls2, -90, d-t, (90, t)] + self.polyline(*(poly + [li-2*t] + list(reversed(poly)))) + + def startwidth(self): + return self.settings.thickness + + +class RegularStarBox(Boxes): + """Regular polygon boxes that form a star when closed""" + + ui_group = "Box" + + + description = """![Open box](static/samples/RegularStarBox-2.jpg)""" + + def __init__(self): + Boxes.__init__(self) + self.addSettingsArgs(edges.FingerJointSettings) + self.buildArgParser("h", "outside") + self.argparser.add_argument( + "--radius", action="store", type=float, default=50.0, + help="inner radius if the box (center to corners)") + self.argparser.add_argument( + "--n", action="store", type=int, default=5, + choices=(3, 4, 5), + help="number of sides") + + def render(self): + + r, h, n = self.radius, self.h, self.n + + if self.outside: + self.r = r = r - self.thickness / math.cos(math.radians(360/(2*n))) + self.h = h = self.adjustSize(h) + + t = self.thickness + + fingerJointSettings = copy.deepcopy(self.edges["f"].settings) + fingerJointSettings.setValues(self.thickness, angle=360./n) + fingerJointSettings.edgeObjects(self, chars="gGH") + + self.edges["e"] = SlotEdge(self, self) + + r, sh, side = self.regularPolygon(n, radius=r) + self.sh = sh + + with self.saved_context(): + self.regularPolygonWall(corners=n, r=r, edges='F', move="right") + self.regularPolygonWall(corners=n, r=r, edges='F', move="right") + + self.regularPolygonWall(corners=n, r=r, edges='F', move="up only") + + for s in range(2): + with self.saved_context(): + if n % 2: + for i in range(n): + self.rectangularWall(side, h, move="right", + edges="fgeG") + else: + for i in range(n//2): + self.rectangularWall(side, h, move="right", + edges="fGeG") + self.rectangularWall(side, h, move="right", + edges="fgeg") + + self.rectangularWall(side, h, move="up only", + edges="fgeG") diff --git a/static/samples/RegularStarBox-2-thumb.jpg b/static/samples/RegularStarBox-2-thumb.jpg new file mode 100644 index 0000000..7f6caa1 Binary files /dev/null and b/static/samples/RegularStarBox-2-thumb.jpg differ diff --git a/static/samples/RegularStarBox-2.jpg b/static/samples/RegularStarBox-2.jpg new file mode 100644 index 0000000..2c3ca3f Binary files /dev/null and b/static/samples/RegularStarBox-2.jpg differ diff --git a/static/samples/RegularStarBox-thumb.jpg b/static/samples/RegularStarBox-thumb.jpg new file mode 100644 index 0000000..ed96d62 Binary files /dev/null and b/static/samples/RegularStarBox-thumb.jpg differ diff --git a/static/samples/RegularStarBox.jpg b/static/samples/RegularStarBox.jpg new file mode 100644 index 0000000..60082a7 Binary files /dev/null and b/static/samples/RegularStarBox.jpg differ diff --git a/static/samples/samples.sha256 b/static/samples/samples.sha256 index 6ff29dc..65c8e00 100644 --- a/static/samples/samples.sha256 +++ b/static/samples/samples.sha256 @@ -94,3 +94,5 @@ b843c04a6ec530afaf40c664479c6f1eeadc9d48f1ff7ca99bea3575da733144 ../static/samp 42aee460ccffbd7487f748e917f9083fb768a7e2b5f3012f57f8f55c20425ea6 ../static/samples/WallPliersHolder.jpg 1ed8dc40cbbbee9f7782f1b19013f4e60201f6bf0775728da43862d2c95418b5 ../static/samples/Platonic-Icosahedron.jpg 207089f5546205c6f812cf95036f9700d15bb9b830ded6a4667689f2af311b89 ../static/samples/SlidingDrawer.jpg +6d7819ccc6851558121b43fca9f3a8dbba632d09091605c97e891ca1e10e51e8 ../static/samples/RegularStarBox.jpg +7ab0da6aa8aa87e72e803bbdc18653622d9f1fb5dd0fe826dbf085bb338e28f6 ../static/samples/RegularStarBox-2.jpg