X-Git-Url: https://git.ao2.it/flexagon-toolkit.git/blobdiff_plain/9e3b6f79607747cd0e42ee5ab93a176f40826067..33f6577dfdb6b5f075c913b0239c5fa20e21b7a5:/src/diagram/diagram.py diff --git a/src/diagram/diagram.py b/src/diagram/diagram.py index eee9fc6..a949577 100755 --- a/src/diagram/diagram.py +++ b/src/diagram/diagram.py @@ -86,3 +86,22 @@ class Diagram(object): apothem_angle = theta + pi / sides return self.draw_star(cx, cy, sides, apothem, apothem_angle, stroke_color) + + def draw_rect(self, x, y, width, height, theta=0, + stroke_color=None, + fill_color=(1, 1, 1, 0.8)): + raise NotImplementedError + + def draw_rect_from_center(self, cx, cy, width, height, theta=0.0, + stroke_color=None, + fill_color=(1, 1, 1, 0.8)): + # the position of the center of a rectangle at (0,0) + mx = width / 2.0 + my = height / 2.0 + + # calculate the position of the bottom-left corner after rotating the + # rectangle around the center + rx = cx - (mx * cos(theta) - my * sin(theta)) + ry = cy - (mx * sin(theta) + my * cos(theta)) + + self.draw_rect(rx, ry, width, height, theta, stroke_color, fill_color)