From 49ce2ed4120c2887cd8dc97080ed2b7a34bb4237 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Sat, 10 Mar 2018 19:28:30 +0100 Subject: [PATCH] New generator: Ottosoles Foam soles for the OttO Bot --- boxes/generators/ottosoles.py | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 boxes/generators/ottosoles.py diff --git a/boxes/generators/ottosoles.py b/boxes/generators/ottosoles.py new file mode 100644 index 0000000..14b7324 --- /dev/null +++ b/boxes/generators/ottosoles.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# Copyright (C) 2013-2018 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 * + +class OttoSoles(Boxes): + """Foam soles for the OttO bot""" + + ui_group = "Misc" + + def __init__(self): + Boxes.__init__(self) + + self.buildArgParser(x=56., y=36.) + self.argparser.add_argument( + "--width", action="store", type=float, default=4., + help="width of sole stripe") + self.argparser.add_argument( + "--chamfer", action="store", type=float, default=5., + help="chamfer at the corners") + self.argparser.add_argument( + "--num", action="store", type=int, default=2, + help="number of soles") + + + def render(self): + x, y = self.x, self.y + c = self.chamfer + c2 = c * 2**0.5 + w = min(self.width, c2 / 2. / math.tan(math.radians(22.5))) + w = self.width + w2 = w * 2**0.5 - c2 / 2 + d = w * math.tan(math.radians(22.5)) + + # Initialize canvas + self.open() + + self.moveTo(0, y, -90) + + for i in range(self.num*2): + if c2 >= 2 * d: + self.polyline(c2, 45, y-2*c, 45, c2/2., 90, w, 90, c2/2-d, -45, + y-2*c-2*d, -45, c2-2*d, -45, x-2*c-2*d, -45, + c2/2-d, 90, w, 90, c2/2., 45, x-2*c, 45) + self.moveTo(0, w + c2/2. + 2*2**0.5*self.burn) + else: + self.polyline(c2, 45, y-2*c, 45, c2/2., 90, w2, 45, + y-2*w, -90, x-2*w, 45, w2, 90, c2/2., 45, x-2*c, 45) + self.moveTo(0, w * 2**0.5 + 2*2**0.5*self.burn) + self.close()