X-Git-Url: https://git.ao2.it/flexagon-toolkit.git/blobdiff_plain/b0d293a76ed3a595754b643f48b2f2d1b03395f6..3c262fada99001bdfe050581a708d1416b0926f2:/src/diagram/cairo_diagram.py diff --git a/src/diagram/cairo_diagram.py b/src/diagram/cairo_diagram.py index 9aab30e..bf35d59 100755 --- a/src/diagram/cairo_diagram.py +++ b/src/diagram/cairo_diagram.py @@ -143,20 +143,6 @@ class CairoDiagram(Diagram): cr.line_to(x2, y2) self._stroke(stroke_color) - 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) - def draw_rect(self, x, y, width, height, theta=0, stroke_color=None, fill_color=(1, 1, 1, 0.8)): @@ -222,84 +208,7 @@ class CairoDiagram(Diagram): def test(): diagram = CairoDiagram(400, 400) - 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)) + Diagram.test(diagram) diagram.show()