Python Patterns

These pages provides source code for creating your own patterns and saving them as Windows Bitmaps (.bmp) files. There is also source code for taking a set of GIF files and converting them into an animated GIF.

The GIF File support is currently limited to sets of files that have the same colour map and are the same size. That was all I needed to create the animations shown later.

The source code can be downloaded from here.

The Patterns

Each source code module includes methods do draw these patterns and includes some example code showing how to use it. The easiest way to generate your own patterns is to vary the parameters in the examples and see what happens. An alternative would to be to create new python scripts based on the example code.

Circle Patterns

This family of patterns is generated from plotting the calculating the z = f(x,y) over a rectangular region and using the value of 'z' to colour in the pixels. I call them circle patterns because the simplest interesting example, generated from z = x2 + y2, generates circles. Click here for a more complete explanation and more, larger examples and animations.

The example code supplied with the module generates larger versions of the following patterns. It can be downloaded from the source code page

Line Patterns

The line pattern module was developed mainly as a test for the line drawing algorithm. It can be used to generate a few patterns similar to these below, These correspond to examples 10, (11,4), 100 and 101.
Eaxmples 1-50 draw what are known as complete graphs (the graph obtained by joining every point in a set to every other point) You can read more about these at Wolfram Research's Mathworld. Passing a tuple such as (11,4) to the 'example' method will draw a star. The third and fourth images are generated by drawing a set of stars (5,2) and (7,1) with different phases and sizes. The source for these patterns can be downloaded from the source code page. To see an animation of the first 29 complete graphs (except 1 and 2) click here.

Spirograph Patterns

The spirograph module simulates the simple drawings that can be generated using the spirograph toy, where one gear wheel rotates around another. A pen can be placed in a hole of one of the wheels and the path followed by the hole generates a rather pleasing pattern. This module can recreate these patterns in software but it can go beyond that and simulate a third wheel rotating around the second and a fourth around the third. As the code is constructed there is no limit to the number of wheels, though it becomes more challenging to choose sets of numbers that produce pleasant patterns. Also, in the toy the rate of rotation of the wheels is constrained by the teeth around the circumference. We have no such constraint, so we can have rapidly rotating large wheels and slowly rotating small ones.

The Spirograph module and the algorithms it uses is described in more detail here. It can generate the bog-standard spirograph patterns like this

or more sophisticated patterns like these (which involve a third wheel).

The spirograph page includes an animation generated using four wheels and there are some four wheel examples you can run.

Some screen backgrounds