Home page

Home Page

Mandelbrots and Julia Sets

Introduction

You can read all about the Mandelbrot Set on Wikipedia.

This section describes the python scripts I have created to generate Mandelbrot and related images.

In the most recent version of the script I've done away with the distinction between Mandelbrot and Julia sets. The new code is generically four dimensional, and allows you to view 2D slices of the combined 4D Mandelbrot+Julia Set obect at any point in 4 space. These slices can be in any of the 6 planes defined by the centre point and two of the vectors (1,0,0,0), (0,1,0,0), (0,0,1,0) and (0,0,0,1). This actually makes the code simpler as we no longer need separate algorithms to generate the Mandelbrot and Julia sets.

Top level view of the 4D object

M Plane This page shows a top level view of the 4D object showing the six orthogonal planes that pass through (0,−1,0,0). Two of these are the familiar Mandelbrot set and the Julia set at c = (−1,0). This page also attempts to explain the 4D geometry that relates these 6 views.

Some 4D examples

Example This page shows images generated as we zoom into the six orthogonal planes.

The Algorithm

The equation to iterate remains

Zn+1 = Zn2 + c

which is iterated until it is obvious that the value of |Z| is approaching infinity (>2 will do) or until we reach the maximum number of iterations we are prepared to try.

In the original code we would set Z0 to (0,0) and vary (cx and cy) to generate a Mandelbrot set, or fix the 'c' value and vary Z0 to generate a Julia set.

The new code does away with this distinction; all 4 co-ordinates are considered equally and we can fix any 2 and vary the other 2. The Julia and Mandelbrot sets are just specific examples from a larger set of possibilities.

Now you choose a point in 4-space (zx,zy,cx,cy) and which of the 6 orthoganal planes you wish to display.

All the colouring schemes and palettes of the previous version are still supported.

The Code

The Mandelbrot source code consists of two files, Mandelbrot.py and MandelbrotDriver.py. (These were last Updated on the 11th October 2008.)

Mandelbrot.py contains the code for drawing the patterns, MandelbrotDriver.py provides a user interface for setting the values.  This can be driven from a command window by typing it directly in (or as I prefer through a batch file) or from the Python IDE. You will also need the Bitmap code in WindowsBMP.py

Assuming you have you paths set up correctly you can run the driver from the command line, the syntax being

python MandelbrotDriver.py <parameters>

Or from within a python environment as

import MandelbrotDriver
MandelbrotDriver.go ("<parameters>")

or by using a list, eg.

import MandelbrotDriver
args = ['-s1280x1024', '-fbig']
MandelbrotDriver.go(args)

Parameters should be separated by spaces and the text in <brackets> should be replaced by actual values. Other characters must appear as shown and there should be no spaces inside parameters. So, for example;

python MandelbrotDriver.py -s1280x1024 -fbig

or

import MandelbrotDriver
MandelbrotDriver.go('-s1280x1024 -fbig')

will draw an image of the whole Mandelbrot set (up to 600 iterations) in a 1280x1024 bitmap called 'big.bmp', saved in the current directory.

The parameters are;

−b<number> The 'blob factor' that controls the level of detail when using the 'stars' or 'bands' colouring algorithm Typical values are quite small, say 0.001.
−c(<zx>,<zy>,<cx>,<cy>) The centre of the image. zx, zy, cx and cy are floating point numbers. For instance around the point −c(0,−.875,−0.075,0.669) you can find images like this.
 
Example
−d<number> Chooses a the drawing colour scheme (1-8).
−f<name> The output file name, without path or extension, eg 'outfile'. Default value is 'mandelbrot'
−h Shows some help on the parameters.
−i<number> Sets the maximum number of iterations. The default value is 600. More on iterations.
−l<number> Ouputs a message after every 'number' rows, allowing you to monitor the progress. Reassuring if you are drawing a very big/deep image.
−m<number> Sets the Magnification. '1' is the whole image, values greater than one zoom in for greater detail. Default value is '1'.
−n "No Draw". If this parameter is specified then the parameter values will be displayed but the image won't be drawn.
−p<path> Sets the path of the output image. Defaults to the current directory.
−s<w>x<h> Sets the image size. Default is 160 by 120, −s1280x1024 will create an image 1280 across and 1024 pixels down.
−t<plane><scheme> The plane of the pattern and the colouring algorithm to use. The 'plane' used to be the 'type', so for backwards compatibility I have retained 'M' for planes parallel to the Mandelbrot plane and 'J' for the planes containing the Julia sets. The other planes are identified using the letters A - D. They are:

Types

A - Fix (zx, cx), vary (zy, cy)
B - Fix (zx, cy), vary (zy, cx)
C - Fix (zy, cx), vary (zx, cy)
D - Fix (zy, cy), vary (zx, cx)
M - Fix (zx, zy), vary (cx, cy) - Set (zx,zy) to (0,0) for the Mandelbrot set.
J - Fix (cx, cy), vary (zx, zy) - Julia sets.
The colouring schemes can be chosen from the following list

Schemes

none - classic colouring algorithm.
S - stars algorithm
B - bands algorithm
R - real bands algorithm
I - imaginary bands algorithm
Q - direction of escape algorithm
−w(x,y) Returns the position of the pixel at (x,y). The image isn't drawn. This will be a 'c' value for Mandelbrots and a 'Z' value for Julia sets. It can be used when deciding where to zoom in on a previously generated image.

Finding Interesting Locations

The following sequence of images shows progresive zooms as we search for an interesting location to display. The search images are only 160x120 so they can be generated quite quickly. The MandelbrotDriver '−w(<x>,<y>)' option can be used to locate the coordinates of an interesting point in an image. This can then be fed into the next iteration with a larger magnification, and the process repeated, producing a sequence like the one below.

Zoom Zoom Zoom Zoom
Zoom Zoom Zoom Zoom

When we have found an interesting location, like the last image in the sequence, we can then create a higher resolution version.

These two images from the Mandelbrot plane centred around −c(0, 0, 0.27322626, 0.595153338) are from one of the AVIs on the animations page.

Example Example

Julia Sets

The Julia Sets reside on the planes doubly perpendicular to to the Mandelbrot plane. Doubly perpendicular as they only share one point in common. They can be drawn using the MandelbrotDriver '−tJ' option. The Julia set for a given 'c' value looks similar to the Mandelbrot around the same value of 'c' (at high zoom). This can be seen in these images for the 'c' value of (−0.3006818, 0.6600910). Settings:

−tM −c(0,0,0.3006818, 0.6600910)
−tJ −c(<x>,<y>,0.3006818, 0.6600910).

Where <x> and <y> represent the co-ordinates of the image centre. The first two are of the Mandelbrot set, the 3rd and 4th details of the corresponding Julia set. In both cases the pattern is built up from strands of detail radiating from 11 pointed intersections. Click on the images for more detail.

Example Example Example Example

Below are some more Julia images for various 'c' values.

Example

Example

Example
Example

Example

Example

This first sequence shows the results of zooming in by a factor of 10, 5 times for the Julia set where 'c' is (0.997837, −0.503156, −0.3006818, 0.6600910). All are 640x480 pixels with an iteration cutoff of 600.

In the final image you can see that the two halves aren't connected. This indicates that 'c' isn't actually inside the Mandelbrot set, so the Julia set will contain an infinite number of distinct points, each of zero size. No amount of zooming will ever find one, though you can see roughly where they are.

 
Example

Example

Example
Example

Example

Example

This sequence is for 'c' = (0, 0, −0.55113284371278159, 0.62783963563277212) and progressively zooms in by factors of 10.

Notice, now that the strands meet in 5 way junctions.

Again we start of with a cutoff of 600 iterations but by the time we have zoomed in a thousand fold we are getting large black regions (4th image). The sequence restarts at x1000 (5th image), but now with the maximum iteration count at 2400 (and the image size increased from 600x480 to 1024x800).

Again, when we zoom in we can see that the pattern becomes disconnected.

The following two Julia images (center and right) correspond to a point near the centre of the black circle at the centre of the Mandelbrot image (left), c = (0, 0, −0.505, 0.570).

Example Example Example

Here the black sections are real, not the consequence of too few iterations. The next set of images is generated round the 'c' value (0, 0, −0.502875, 0.518925). The image on the left is the Mandelbrot, the 2nd and 3rd the corresponding Julia images. You can click on the Julia images for more detail.

This final set of images is an example of how you can find regions of the set that are too complicated to render clearly on a screen. The spiral pattern has 47 spokes radiating from a point. By choosing points in the "Seahorse Vallies", places on the Mandelbrot set where two black circles appear to meet, you can find spirals with any (odd) number of spokes you like.

Example  Example   Example

(c) John Whitehouse 2011