tregular star polygons and plot_all_to_all work - polygen - generative drawing of polygonal patterns
 (HTM) git clone git://src.adamsgaard.dk/polygen
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 81f436d4572ead5ff4f86d0e89547527dc20fd5d
 (DIR) parent aadea4129d9099b7ae7bb74c8bb8ba32c75b631c
 (HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
       Date:   Thu, 13 Mar 2014 20:49:11 +0100
       
       regular star polygons and plot_all_to_all work
       
       Diffstat:
         M polygen.py                          |      51 +++++++++++++++++++++++++------
       
       1 file changed, 42 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/polygen.py b/polygen.py
       t@@ -2,15 +2,48 @@
        import numpy
        import matplotlib.pyplot as plt
        
       -class polygen:
       -    def __init__():
       -        points = []
       +class polyplot:
       +    def __init__(self):
       +        self.points = []
        
       -    def add_point(self, x, y):
       -        self.points.append(numpy.array(x, y))
       +    def add_point(self, xy_point):
       +        self.points.append(numpy.asarray(xy_point))
        
       -    def plot_all_to_all(self, line_color='k', line_width=2):
       +    def set_points(self, points):
       +        self.points = points
       +
       +    def plot_all_to_all(self, line_color='k', line_width=2,
       +            image_name='all_to_all', image_format='png'):
       +        self.points = numpy.asarray(self.points)
                fig = plt.figure()
       -        for point_a in self.points:
       -            for point_b in self.points:
       -                plt.plot(point_a, point_b, line_color + '-', lw=line_width)
       +        for i in range(self.points.shape[0]):
       +            for j in range(self.points.shape[0]):
       +                if (i != j):
       +                    plt.plot([self.points[i,0], self.points[j,0]],
       +                            [self.points[i,1], self.points[j,1]],
       +                            line_color + '-', lw=line_width)
       +        print(self.points)
       +        plt.plot(self.points[:,0], self.points[:,1], 'ro')
       +        plt.axis('equal')
       +        fig.savefig(image_name + '.' + image_format)
       +        fig.clf()
       +
       +class regular_star_polygon:
       +    def __init__(self, n=5):
       +
       +        if (n < 3):
       +            raise Exception('regular_star_polygon: Error, this function ' +
       +            'doesn\'t work with n < 3.')
       +
       +        self.n = n
       +        self.generate_regular_star_polygon()
       +
       +    def generate_regular_star_polygon(self, radius=1.0):
       +        self.points = numpy.empty((self.n, 2))
       +
       +        for i in range(self.n):
       +            theta = i*(2.0*numpy.pi/self.n)
       +            x = radius*numpy.cos(theta)
       +            y = radius*numpy.sin(theta)
       +            self.points[i,0] = x
       +            self.points[i,1] = y