X-Git-Url: https://git.ao2.it/flexagon-toolkit.git/blobdiff_plain/b0d293a76ed3a595754b643f48b2f2d1b03395f6..3c262fada99001bdfe050581a708d1416b0926f2:/src/diagram/diagram.py diff --git a/src/diagram/diagram.py b/src/diagram/diagram.py index eee9fc6..43e3a93 100755 --- a/src/diagram/diagram.py +++ b/src/diagram/diagram.py @@ -32,6 +32,87 @@ class Diagram(object): raise NotImplementedError @staticmethod + def test(diagram): + diagram.clear() + + x = 40 + y = 200 + + x_offset = x + + theta = 0 + + diagram.draw_line(0, y, 400, y, (1, 0, 0, 1)) + + advance = diagram.draw_centered_text(x_offset, y, "Ciao", theta, + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + advance = diagram.draw_centered_text(x_offset, y, "____", theta + pi / 4, + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + advance = diagram.draw_centered_text(x_offset, y, "jxpqdlf", theta + pi / 2, + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + advance = diagram.draw_centered_text(x_offset, y, "pppp", theta + 3 * pi / 4, + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + advance = diagram.draw_centered_text(x_offset, y, "dddd", theta + pi, + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + advance = diagram.draw_centered_text(x_offset, y, "Jjjj", theta + 5 * pi / 4, + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + advance = diagram.draw_centered_text(x_offset, y, "1369", theta + 3 * pi / 2, + color=(0, 1, 0), + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + advance = diagram.draw_centered_text(x_offset, y, "qqqq", theta + 7 * pi / 4, + align_baseline=True, + bb_stroke_color=(0, 0, 0, 0.5), + bb_fill_color=(1, 1, 1, 0.8)) + x_offset += advance + + diagram.draw_rect(40, 40, 300, 100, stroke_color=(0, 0, 0, 0.8)) + diagram.draw_rect(40, 40, 300, 100, pi / 30, stroke_color=(0, 0, 0, 0.8)) + + verts = diagram.draw_regular_polygon(190, 90, 3, 20) + + diagram.draw_rect(40, 250, 300, 100, stroke_color=(0, 0, 0, 0.8)) + diagram.draw_rect_from_center(40 + 150, 250 + 50, 300, 100, theta=(pi / 40), + stroke_color=(1, 0, 0), + fill_color=None) + + verts = diagram.draw_regular_polygon(190, 300, 6, 20, pi / 3., (0, 0, 1, 0.5), (0, 1, 0.5)) + diagram.draw_apothem_star(190, 300, 6, 20, 0, (1, 0, 1)) + + diagram.draw_star_by_verts(190, 300, verts, (1, 0, 0, 0.5)) + diagram.draw_star(190, 300, 6, 25, 0, (1, 0, 1, 0.2)) + + diagram.draw_circle(190, 300, 30, (0, 1, 0, 0.5), None) + diagram.draw_circle(100, 300, 30, (1, 0, 0, 0.5), (0, 1, 1, 0.5)) + + @staticmethod def color_to_rgba(color): assert len(color) >= 3 @@ -86,3 +167,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)