X-Git-Url: https://git.ao2.it/experiments/RadialSymmetry.git/blobdiff_plain/3286ef9194ac827cfa6d93aac6036214631f69c9..350bd1d7d169f60f20ab95e1d7a117d48dea3b87:/Diagram.py diff --git a/Diagram.py b/Diagram.py index 7d6348b..74c3bb2 100755 --- a/Diagram.py +++ b/Diagram.py @@ -97,52 +97,58 @@ class Diagram(object): else: return None - def draw_polygon(self, verts, stroke_color=[0, 0, 0], fill_color=None): + def _draw_polygon(self, verts): cr = self.cr - if fill_color: - v = verts[0] - cr.move_to(v[0], v[1]) - for v in verts[1:]: - cr.line_to(v[0], v[1]) - cr.close_path() + v = verts[0] + cr.move_to(v[0], v[1]) + for v in verts[1:]: + cr.line_to(v[0], v[1]) + cr.close_path() + + def draw_polygon(self, verts, fill_color=None, stroke_color=[0, 0, 0]): + cr = self.cr + if fill_color: + self._draw_polygon(verts) r, g, b, a = self.color_to_rgba(fill_color) cr.set_source_rgba(r, g, b, a) cr.fill() - n = len(verts) - for i in range(0, n): - v1 = verts[i] - v2 = verts[(i + 1) % n] - cr.move_to(v1[0], v1[1]) - cr.line_to(v2[0], v2[1]) - - r, g, b, a = self.color_to_rgba(stroke_color) - cr.set_source_rgba(r, g, b, a) - cr.stroke() + if stroke_color: + self._draw_polygon(verts) + r, g, b, a = self.color_to_rgba(stroke_color) + cr.set_source_rgba(r, g, b, a) + cr.stroke() def draw_star(self, cx, cy, verts, stroke_color=[0, 0, 0]): cr = self.cr - v = verts[0] - cr.move_to(cx, cy) for v in verts: - cr.line_to(v[0], v[1]) cr.move_to(cx, cy) + cr.line_to(v[0], v[1]) r, g, b, a = self.color_to_rgba(stroke_color) cr.set_source_rgba(r, g, b, a) cr.stroke() - def draw_dot(self, cx, cy, size=10.0, fill_color=[0, 0, 0, 0.5]): + def draw_circle(self, cx, cy, size=10.0, fill_color=[0, 0, 0, 0.5], + stroke_color=None): cr = self.cr cr.save() - r, g, b, a = self.color_to_rgba(fill_color) - cr.set_source_rgba(r, g, b, a) cr.arc(cx, cy, size, 0, 2 * pi) - cr.fill() + + if fill_color: + r, g, b, a = self.color_to_rgba(fill_color) + cr.set_source_rgba(r, g, b, a) + cr.fill() + + if stroke_color: + r, g, b, a = self.color_to_rgba(stroke_color) + cr.set_source_rgba(r, g, b, a) + cr.stroke() + cr.restore() def normalized_angle_01(self, theta): @@ -150,10 +156,10 @@ class Diagram(object): def draw_line(self, x1, y1, x2, y2, stroke_color=[0, 0, 0, 1]): cr = self.cr - r, g, b, a = self.color_to_rgba(stroke_color) - cr.set_source_rgba(r, g, b, a) cr.move_to(x1, y1) cr.line_to(x2, y2) + r, g, b, a = self.color_to_rgba(stroke_color) + cr.set_source_rgba(r, g, b, a) cr.stroke() def draw_rect_from_center(self, cx, cy, width, height, theta=0, @@ -192,7 +198,6 @@ class Diagram(object): r, g, b, a = self.color_to_rgba(stroke_color) cr.set_source_rgba(r, g, b, a) cr.stroke() - self.draw_dot(0, 0, 3.0, stroke_color) cr.restore()