boxespy/boxes/generators/ottosoles.py

67 lines
2.4 KiB
Python
Raw Normal View History

#!/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 <http://www.gnu.org/licenses/>.
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:
2018-03-11 09:13:40 +01:00
self.polyline((c2, 1), 45, (y-2*c, 1), 45, c2/2., 90, (w, 1),
90, c2/2-d, -45, (y-2*c-2*d, 1), -45,
(c2-2*d, 1), -45,
(x-2*c-2*d, 1), -45, c2/2-d, 90, (w, 1), 90,
c2/2., 45, (x-2*c, 1), 45)
self.moveTo(0, w + c2/2. + 2*2**0.5*self.burn)
else:
2018-03-11 09:13:40 +01:00
self.polyline((c2, 1), 45, (y-2*c, 1), 45, c2/2., 90, (w2, 1),
45, (y-2*w, 1), -90, (x-2*w, 1), 45, (w2, 1), 90,
c2/2., 45, (x-2*c, 3), 45)
self.moveTo(0, w * 2**0.5 + 2*2**0.5*self.burn)
self.close()