Contents

Download

CirclePattern is implemented in the module CirclePattern.py

Explanation

The circle pattern is generated by trying to render the surface z = k(x2 + y2) using a square grid and a finite number of colours. For very small pixels and a large range of colours you get some quite smooth circles.

Smooth This was created using the script

import CirclePattern
import ColourMap
pat = CirclePattern.CirclePattern()
pat.setSize (240,160)
pat.createColourMap(ColourMap.blue,ColourMap.cyan,64)
pat.z_factor = 0.01
pat.draw()
pat.bitmap.writeFile(pat.path+'smooth.bmp')

'z_factor' is the term that appears as 'k' in the original equation. Reducing the number of colours while keeping everything else the same produces a more ragged pattern and interesting interference effects start appearing, producing the ghost circles around the central one, as can be seen in the next image.

Smooth This was created using the script

import CirclePattern
import ColourMap
pat = CirclePattern.CirclePattern()
pat.setSize (240,160)
pat.createColourMap(ColourMap.blue,ColourMap.cyan,8)
pat.z_factor = 0.01
pat.draw()
pat.bitmap.writeFile(pat.path+'smooth2.bmp')

Increasing the 'z' factor (k) also tightens the circles and more ghost effects appear as can be seen in this animation.

Z This was created using the script

import CirclePattern
import ColourMap
pat = CirclePattern.CirclePattern()
pat.setSize (240,160)
pat.createColourMap(ColourMap.blue,ColourMap.cyan,8)
pat.filename = 'sequence'
pat.drawZSequence(0.01,0.005,1,20)

The script creates a sequence of 20 images with z_factors [0.01, 0.015, 0.02, ...] and filenames ['sequence00001.bmp', ...]. I converted these to GIFs using Paintshop Pro giving ['sequence00001.gif', ...] and then animated them using the following python script;

import MakeFileList
import GIFAnimator
flist=MakeFileList.MakeFileList(pat.path, 'sequence', 'gif', 1, 20) 
gif=GIFAnimator.buildFromFiles(flist)
gif.writeToFile(pat.path+'seq1.gif')

These examples are small to save bandwidth, you can create larger images and longer animations for yourself.

Related Paterns

If you examine the circle pattern code you will see that the CirclePattern

self.fun = self.circle

and that the code that calculates the pattern calls 'fun' rather than 'circle'. You can use this to quickly change the equation that is drawn. The functions available are listed in the Supplied Functions section but it is easy to add new ones. The function 'anticircle' is shown in the next example.

Anticircle

Script:

import CirclePattern
import ColourMap
pat = CirclePattern.CirclePattern()
pat.setSize (240,160)
pat.createColourMap(ColourMap.blue,ColourMap.cyan,8)
pat.z_factor = 0.01
pat.fun=pat.anticircle
pat.draw()
pat.bitmap.writeFile(pat.path+'smooth2.bmp')

Drawing the XY Sequence

The function

drawXYSequence (self, xy0, xyinc, start, num):

creates a sequence of patterns by varying xy_factor. You must set pat.fun to be 'xyfun' to use this.

Click here to see some examples.

The 'example' function

The CirclePattern module includes an example function which can be used to create a few example patterns.  This is easily edited if you want to experiment. It is accessed using script like

import CirclePattern
pat=CirclePattern.example(1)

which will create a file called 'example1.bmp'. There are six basic examples (1-6) and a example sequence (1000). You can generate all the standard examples in one go with the script.

import CirclePattern
for i in range (1,7):
    CirclePattern.example(i)

They generate larger versions of the following patterns.

Example 1 Example 2 Example 3 Example 4 Example 5 Example 6

The CirclePattern Class

Hopefully the code is commented well enough for you to follow it and I've tried to avoid complicated statements. I'll just explain the class member variables here;

self.width = 400 The width of the pattern in cells. The width in pixels will be this value multiplied by self.blocksize
self.height = 300 The height of the pattern in cells. The height in pixels will be this value multiplied by self.blocksize
self.colour_map = [black,white] The colour map. A list of colours. The createColourMap can be used to initialise this to a range of colours or you can build up the map from individual colours in any pattern you like.
self.z_factor = 1e-3 The vakue of 'k' in the various equations.
self.xy_factor = 0 The value of 'k2' in the various equations.
self.path = 'c:\\python23\\work\\' The folder where the output files are saved.
self.filename = 'circle' The name part of an output file. The final name will be

self.path+self.filename+index+'.bmp', where 'index' is the file number.
self.blocksize = 1 The size of the cells in the drawing. They are always square.
self.fun = self.circle The function to use to calculate the pattern.

Supplied Functions

The following functions are supplied with the code. Others can easily be added.

circle (default)   z_factor * (x * x + y * y)
anticircle  z_factor * (x * x - y * y)
xyfun  z_factor * (x * x + xy_factor * x * y + y * y)
x3y3 z_factor * (x * x * x + y * y * y)
x4y4 z_factor * (x * x * x * x + y * y * y * y)
x3y3_xy z_factor * (x * x * x + y * y * y) / (x * y)
xpy_xmy z_factor * (x + y) / (x - y)

The equations with a division will return 0 if the denominator is 0.

Other pages

 

(c) John Whitehouse 2011 - 2017