polygen

Generative drawing of polygonal patterns
git clone git://src.adamsgaard.dk/polygen
Log | Files | Refs

commit f51f9c0287d3176bb8fa818db4035b3ddf41413c
parent ba5bec68d87be35cff72f57af2ea41062f9760ef
Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date:   Thu, 13 Mar 2014 21:39:26 +0100

Added background color control

Diffstat:
Moctahedron.py | 4+---
Mpolygen.py | 20++++++++++++++------
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/octahedron.py b/octahedron.py @@ -1,10 +1,8 @@ #!/usr/bin/env python - -import numpy import polygen octahedron = polygen.regular_star_polygon(8) -#octahedron = polygen.regular_star_polygon(3) p = polygen.polyplot() p.set_points(octahedron.points) p.plot_all_to_all(line_width=4, exceptions=[[0,4], [1,5], [2,6], [3,7]]) +p.save_plot(background_color='#666666', transparent_background=False) diff --git a/polygen.py b/polygen.py @@ -13,12 +13,11 @@ class polyplot: self.points = points def plot_all_to_all(self, line_color='k', line_width=2, - image_name='all_to_all', image_format='png', - figure_size=(8,8), transparent_background=True, + figure_size=(8,8), plot_points=False, points_style='wo', show_axes=False, exceptions=[]): self.points = numpy.asarray(self.points) - fig = plt.figure(figsize=figure_size) + self.fig = plt.figure(figsize=figure_size) for i in range(self.points.shape[0]): for j in range(self.points.shape[0]): if (i != j and @@ -32,9 +31,18 @@ class polyplot: plt.axis('equal') if (show_axes == False): plt.axis('off') - fig.savefig(image_name + '.' + image_format, - transparent=transparent_background) - fig.clf() + + def save_plot(self, image_name='all_to_all', image_format='png', + background_color='white', + transparent_background=False): + if (transparent_background == True): + self.fig.savefig(image_name + '.' + image_format, + transparent=True) + else: + self.fig.savefig(image_name + '.' + image_format, + facecolor=background_color, transparent=False) + self.fig.clf() + class regular_star_polygon: def __init__(self, n=5):