X-Git-Url: https://git.ao2.it/experiments/RadialSymmetry.git/blobdiff_plain/cec24af99e45a904818d143fbeafc6d795eb2fe5..b1560e48352bc9862c8c250717532d6fc03db740:/Diagram.py?ds=sidebyside diff --git a/Diagram.py b/Diagram.py index b6de388..e2d85d5 100755 --- a/Diagram.py +++ b/Diagram.py @@ -106,7 +106,7 @@ class Diagram(object): cr.line_to(v[0], v[1]) cr.close_path() - def draw_polygon(self, verts, fill_color=None, stroke_color=[0, 0, 0]): + def draw_polygon_by_verts(self, verts, fill_color=None, stroke_color=[0, 0, 0]): cr = self.cr if fill_color: @@ -121,7 +121,11 @@ class Diagram(object): cr.set_source_rgba(r, g, b, a) cr.stroke() - def draw_star(self, cx, cy, verts, stroke_color=[0, 0, 0]): + def draw_polygon(self, cx, cy, sides, r, theta=0.0, fill_color=None, stroke_color=[0, 0, 0]): + verts = self.get_regular_polygon(cx, cy, sides, r, theta) + self.draw_polygon_by_verts(verts, fill_color, stroke_color) + + def draw_star_by_verts(self, cx, cy, verts, stroke_color=[0, 0, 0]): cr = self.cr for v in verts: @@ -132,6 +136,13 @@ class Diagram(object): cr.set_source_rgba(r, g, b, a) cr.stroke() + def draw_star(self, cx, cy, sides, r, theta=0.0, stroke_color=[0, 0, 0]): + apothem = r * cos(pi / sides) + apothem_angle = theta + pi / sides + + verts = self.get_regular_polygon(cx, cy, sides, apothem, apothem_angle) + self.draw_star_by_verts(cx, cy, verts, stroke_color) + def draw_circle(self, cx, cy, size=10.0, fill_color=[0, 0, 0, 0.5], stroke_color=None): cr = self.cr @@ -202,8 +213,8 @@ class Diagram(object): def draw_centered_text(self, cx, cy, text, theta=0, color=[0, 0, 0], align_baseline=False, - bb_fill=True, bb_fill_color=[1, 1, 1, 0.8], - bb_stroke=False, bb_stroke_color=[0, 0, 0, 0.5]): + bb_fill_color=[1, 1, 1, 0.8], + bb_stroke_color=None): cr = self.cr x_bearing, y_bearing, width, height, x_advance = cr.text_extents(text)[:5] @@ -259,28 +270,28 @@ if __name__ == "__main__": theta = 0 - advance = diagram.draw_centered_text(x_offset, y, "Ciao", theta, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "Ciao", theta, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance - advance = diagram.draw_centered_text(x_offset, y, "____", theta + pi / 4, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "____", theta + pi / 4, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance - advance = diagram.draw_centered_text(x_offset, y, "jxpqdlf", theta + pi / 2, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "jxpqdlf", theta + pi / 2, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance - advance = diagram.draw_centered_text(x_offset, y, "pppp", theta + 3 * pi / 4, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "pppp", theta + 3 * pi / 4, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance - advance = diagram.draw_centered_text(x_offset, y, "dddd", theta + pi, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "dddd", theta + pi, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance - advance = diagram.draw_centered_text(x_offset, y, "Jjjj", theta + 5 * pi / 4, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "Jjjj", theta + 5 * pi / 4, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance - advance = diagram.draw_centered_text(x_offset, y, "1369", theta + 3 * pi / 2, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "1369", theta + 3 * pi / 2, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance - advance = diagram.draw_centered_text(x_offset, y, "qqqq", theta + 7 * pi / 4, align_baseline=True, bb_stroke=True) + advance = diagram.draw_centered_text(x_offset, y, "qqqq", theta + 7 * pi / 4, align_baseline=True, bb_stroke_color=[0, 0, 0, 0.5]) x_offset += advance diagram.draw_line(0, y, 400, y, [0, 0, 1, 0.2])