Diagram.py: add a draw_polygon() wrapper which also calculate vertices
authorAntonio Ospite <ao2@ao2.it>
Thu, 18 Jun 2015 10:26:05 +0000 (12:26 +0200)
committerAntonio Ospite <ao2@ao2.it>
Thu, 18 Jun 2015 10:26:05 +0000 (12:26 +0200)
Diagram.py
RadialSymmetryDiagram.py

index 4e14b1c..cb4bde1 100755 (executable)
@@ -106,7 +106,7 @@ class Diagram(object):
             cr.line_to(v[0], v[1])
         cr.close_path()
 
             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:
         cr = self.cr
 
         if fill_color:
@@ -121,6 +121,10 @@ class Diagram(object):
             cr.set_source_rgba(r, g, b, a)
             cr.stroke()
 
             cr.set_source_rgba(r, g, b, a)
             cr.stroke()
 
+    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(self, cx, cy, verts, stroke_color=[0, 0, 0]):
         cr = self.cr
 
     def draw_star(self, cx, cy, verts, stroke_color=[0, 0, 0]):
         cr = self.cr
 
index e21694b..09a3638 100755 (executable)
@@ -66,7 +66,7 @@ class RadialSymmetryDiagram(Diagram.Diagram):
                                          base_polygon_orientation)
 
         if model.show_base_polygon:
                                          base_polygon_orientation)
 
         if model.show_base_polygon:
-            self.draw_polygon(verts, None, [0, 0, 0])
+            self.draw_polygon_by_verts(verts, None, [0, 0, 0])
 
         for i, v in enumerate(verts[:]):
             radial_orientation_angle = (i + 1) * central_angle
 
         for i, v in enumerate(verts[:]):
             radial_orientation_angle = (i + 1) * central_angle
@@ -95,8 +95,8 @@ class RadialSymmetryDiagram(Diagram.Diagram):
 
     def draw_element(self, x, y, model, theta, color=[0, 0, 0]):
         if model.show_elements:
 
     def draw_element(self, x, y, model, theta, color=[0, 0, 0]):
         if model.show_elements:
-            tverts = self.get_regular_polygon(x, y, model.element_sides, model.element_radius, theta)
-            self.draw_polygon(tverts, None, color)
+            self.draw_polygon(x, y, model.element_sides, model.element_radius,
+                              theta, None, color)
 
         if model.show_stars:
             apothem = model.element_radius * cos(pi / model.element_sides)
 
         if model.show_stars:
             apothem = model.element_radius * cos(pi / model.element_sides)