Home page

Home Page

Source Code

This is all published as ASCII text files. You will need to download a python environment to use it. I use the PythonWin IDE from ActiveState. It should be free and comes with lots of documentation. Python is an interpreted language, so it isn't lightening fast. For better performance you could always translate these algorithms into faster languages, such as 'C'.

File Handling

These files contain source code for handling various graphics file formats.

WindowsBMP.py This file handles windows bitmap files. It supports loading and saving plus a few simple transformations. It also has methods to set pixel colours and is used by all the pattern drawing applications.

Currently only 24 bit encoding is supported completely.
GIFFile.py
GIFHeader.py
GIFGraphicControlExtension.py
GIFImage.py
GIFApplicationExtension.py
GIFCommentExtension.py
GIFDataSubBlock.py
These files are used for reading and writing GIF files. These is no support for compressing or decompressing the image data.

They do let you peek inside the files and you can add remove or edit the comment records. You can aslo alter the speed and repeat counts for animated GIFs.
GIFAnimator.py This file enables you to convert a set of GIF files into an animated GIF. It currently only supports series of files that all have the same colour map and are the same size, like those that are output by some of the examples included in the pattern code.

Utilities

These files contain functions used in the patterns, but don't draw patterns themselves.

MakeFileList.py This creates a list of files with incremental names. These are useful for generating animations. For instance the script

MakeFileList.MakeFileList ('c:\\', 'pic', 'gif', 1, 4)

Generates the file names

c:\pic00001.gif
c:\pic00002.gif
c:\pic00003.gif
c:\pic00004.gif
ColourMap.py This is used to generate ranges of colours. It also defines a few. It is used a lot in the CirclePatterns module, eg

colour_map = ColourMap.createLinear (ColourMap.green, ColourMap.blue, 4)

creates a list of four colours spread evenly between blue and green. Colours are encoded as three character strings so the above map looks like

['\x00\xff\x00', 'U\xaa\x00', '\xaaU\x00', '\xff\x00\x00']
LineDrawer.py This Constructs the set of pixels to draw a line between
two points. It is used by various patterns to draw straight lines.

The line following algorithm basically calculates the value of

Z = Ax + By + C

for candidate points along the line and chooses the next point to be the candidate where Z is closest to zero. Because we start at a point on the line (where Z = 0) and calculate the candidate values by adding the derivatives (dz/dx and dz/dy) we don't need to know the value of C.

The Patterns

CirclePattern.py Draws the "Circle Pattern" family of patterns.
LinePattern.py Draws the "Line Pattern" family of patterns.
SpirographDriver.py Spirograph.py Draws Spirographs and related patterns.

(c) John Whitehouse 2011