Diagram.py: return the vertices from draw_polygon() and draw_star()
[experiments/RadialSymmetry.git] / Diagram.py
index 4e14b1c..aa6e659 100755 (executable)
@@ -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,12 @@ 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)
+        return verts
+
+    def draw_star_by_verts(self, cx, cy, verts, stroke_color=[0, 0, 0]):
         cr = self.cr
 
         for v in verts:
@@ -132,6 +137,14 @@ 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)
+            return verts
+
     def draw_circle(self, cx, cy, size=10.0, fill_color=[0, 0, 0, 0.5],
                     stroke_color=None):
         cr = self.cr