Python Script

This page allows you to download the python script to generate pictures of you own. The script itself is rather complicated so I'm not going to try and explain how it works. Using it, though, is quite simple.

The Script

You will need to download the following files and save them in your python path. The first 5 are for calculating the patterns, the last three render them to bitmaps.

Instructions

The following code snippet shows how to start off a pattern. The layout is taken from the ActiveState Python IDE, see http://www.activestate.com/Products/ActivePython/. I use version 2.3, I've not tested this on more recent versions.

>>> import SPattern
>>> pattern = SPattern.SPattern()
>>> pattern.start(13,1)
>>> pattern.draw(160,'spokes13')

"import Spattern"

loads all the modules into the environment.

"pattern=SPattern.SPattern()"

creates a pattern object called "pattern". You only need to do the first two statements once per session, you can reuse the pattern object.

"pattern.start (13,1)"

initialises the pattern to a 13 sided polygon with radial spokes. (13,0) would create a polygon without the spokes.

"pattern.draw(160,'spokes13')"

draws the pattern to a bitmap called 'spokes13.bmp'. The module "Spattern.py" contains a statement like

def_path = 'c:/python23/work/shapes/'

which identifies where the patterns are saved. To save them somewhere else you need to edit the file and change this before importing the "Spattern" module into the environment. "160" defines the size of the bitmap. The result looks like this.

To create the next pattern in the sequence use the "nextPattern" function. This replaces the current pattern with the next one in the sequence.

>>> pattern.nextPattern()
>>> pattern.draw(320,'spokes13b')

Which looks like this.

Note: You don't have to draw the pattern after every iteration.

Advanced Users

If you aren't interested in printing out the intermediate steps you can you use the short-cut

>>> import SPattern
>>> pattern = SPattern.makePattern (13,1,1)
>>> pattern.draw(320,'spokes13b')

which combines the above operations into a single function call: makePattern. The first parameter is the symettry value, '13'. The second is whether or not we want spokes, '1' is yes. The third parameter is the number of times to apply the nextPattern algorithm. The above sequence will recreate the 'spokes13b' pattern described above.

The Dual Function

The "getDual" function can be used to obtain the dual of the current pattern. Note that this creates a new object (called "dual" in this example), the original pattern, called "pattern", still exists.

>>> dual=pattern.getDual()
>>> dual.draw(320,'spokes13bd')

The dual looks like this.

You can now continue iterating with the dual or the original pattern, for instance

>>> pattern.nextPattern()
>>> dual.nextPattern()
>>> pattern.draw(320,'spokes13c')
>>> dual.draw(320,'spokes13bd2')

Produces these two images

We can go mad and take duals again

>>> d2=pattern.getDual()
>>> d3=dual.getDual()
>>> d2.draw(320,'spokes13cd')
>>> d3.draw(320,'spokes13bd2d')

or we can start again.

>>> pattern = SPattern.makePattern(6,0,0)
>>> pattern.draw(160,'nospokes6')

Instructions

There is a new starting method, startGrid, which allows you to start with a square array of squares. It is used in place of "start" as shown in this example.

>>> import SPattern
>>> pattern = SPattern.SPattern()
>>> pattern.startGrid(4)
>>> pattern.draw(160,'grid4')

This example creates the starting pattern

Which can then be manipulated in the same was as the other starting patterns. See the Colouring in page for an example.

The Relaxation algorithm.

The relaxation algorithm has been used to generate the animations on the animations pages, for instance, on this page, we have the code

>>> dual.relax(300,0,100,True,300)

The parameters are:

  1. The number of iterations (300 in this example).
  2. The damping (zero is no damping so the pattern will continue oscillating for ever, 1 is 100% damping, the animation will proceed as if it was embedded in treacle. Values outside this range will accelerate the oscillations.
  3. A scaling factor. Used to ensure that the individual steps in the calculations are small compared to the average line length. 100 means that the steps will be about 1% of the line length. 50 will be 2%.
  4. The fourth parameter (True above) indicates whether or not the intermediate patterns are drawn to files. Set this to True if you want to create an animation, False if you are only interested in the end product. The files will be called "relax<n>.bmp", with <n> starting at 0.
  5. The size of the images drawn, if the 4th parameter is True.

Visits since April 2005: