Mandelbrots and Julia Sets

Contents

Description

These two types of fractal are included together in the same module as they are derived from the same equation.

Zn+1 = Zn2 + c

This equation is iterated until it is obvious that the value of Z is approaching infinity (>2 will do) or until we loose interest. In the examples that follow we tend to give up if Z2400 is still less than 2. Z and c are complex numbers, so we really mean |Z2400| < 2. If |Z| becomes greater than 2, we count the number of iterations that have passed and use this to choose a colour. If, after we've iterated more times than we care to, we still haven't passed 2 we assume the point is inside the set and colour it black. If you try generating your own patterns you will find that the further you zoom in the larger iteration cut-off you will need to draw decent patterns. The following two images illustrate the effect of changing the maximum number of iterations from 16 to 2400. In this case 2400 is probably too many, but 16 clearly isn't enough. If you choose too many the image will take ages to draw but otherwise will be ok.
16 iterations 2400 iterations
These pictures also illustrate the advantage of the new colouring algorithm. The locations of the colour bands no longer change depending on the number of iterations, so if you want to create a series of zoomed images you can increase the number of iterations as you go without loosing continuity. They were created with the new "-d8" colour scheme, as was the image on the right, it's 5000x3750 pixels!

The number of iterations required before a point is clearly diverging depends on the two starting values (Z0 and c). As both of these are complex numbers we have four independent variables Zx, Zy, Cx and Cy, where x and y represent the real and imaginary parts of the complex number. I use x and y rather than r and i as they relate more obviously to the 2D images we are generating.

If we lived in a five dimensional universe and had four dimensional computer screens to stare at, we could study the effect of varying all four parameters, and would see on our screens an interesting 4 dimensional shape surrounded by waves of colour. Being a 3D being I personally find it rather hard to imagine what this 4D object actually looks like, instead I have to satisfy myself with looking at 2D slices. Generating this 4D shape could take some time too, as a 1000x1000x1000x1000 pixel screen would have a trillion elements and require 4 terabytes to store the image (32 bit uncompressed).

One obvious slice to draw  is where Z0 = (0,0). Here we are free to vary Cx and Cy over whatever ranges we like and study the patterns generated. If we use the values of Cx and Cy as coordinates and plot the number of iterations before |Z| > 2 we get the familiar Mandelbrot image. We can zoom into this indefinitely, seeing more and more complexity, until the detail gets too much for the computer screen to render.

Alternatively, we may choose to pick a particular value of 'c' and vary the starting value of Z. There are an infinite number of 'c' values and each one produces a different pattern. These are referred to as the Julia sets. Every point on the Mandelbrot image has a corresponding Julia set. Interestingly, if 'c' is in the black point in the Mandelbrot then the black part of the Julia set will be joined up, whereas if you choose a point from the coloured region the Julia set will be an infinite number of islands. The example below is in this region as can be seen in the 4th image.

The Code

The Mandelbrot source code can be downloaded here - Mandelbrot.py and MandelbrotDriver.py. (UPdated 29 June 2008)

Mandelbrot contains the code for drawing the patterns, MandelbrotDriver provides a user interface for setting the values.  This can be driven from a command line or from the Python IDE. Mandelbrot also a list of interesting points to zoom in on and some alternative colour schemes. These can all be easily modified/extended. 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>

Currently defined parameters are;

−a<number> Sets the 'c' value to one of the predefined interesting points (0-5). Default value is 0.
−b<number> The 'blob' or star facture that controls the level of detail when using the 'stars' or 'bands' colouring scheme,  see colour schemes.
−c(<x>,<y>) Sets the 'c' value. For Julia sets this applies to the whole image, for Mandelbrots it is the centre of the image. If this isn't set then the point indicated by the '-a' parameter is used.
−d<number> Chooses a the drawing colour scheme (1-8), see colour schemes.
−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. Default value is 600.
−l Ouputs a message after every row is drawn so that you can monitor 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 160x120.
−t<type> The type of pattern and the colouring algorithm

Mandelbrot Set

−tM - classic colouring algorithm
−tMS - stars algorithm
−tMB - bands algorithm
−tMR - real bands algorithm
−tMI - imaginary bands algorithm
−tMQ - direction of escape algorithm

Julia Sets

−tJ - classic colouring algorithm
−tJS - stars algorithm
−tJB - bands algorithm
−tJR - real bands algorithm
−tJI - imaginary bands algorithm
−tJQ - 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.
−z(x,y) The drawing centre for Julia sets. For Mandelbrots this is the Z0 value. To draw a proper Mandelbrot it should be left at the default value of 0, but some interesting patterns can be generated using other values of Z0 (see the Other Sets section).

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

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 driver can also be invoked from the Python IDE, eg

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

or

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

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' option can be used to locate the coordinates of an interesting point in an image, which can then be fed into the next iteration with a larger magnification.

The final image is a link to a higher resolution version.

Mandelbrot Images

Some images from Point 2, c = (0.27322626, 0.595153338).

This next sequence of images demonstrates one of the alternative colour palettes (-d4). See the colour schemes page for an explanation of palettes.

x50

 

x100 x200
x400 x1600
x8000

More Mandelbrot images can be found in the Julia Set section.

Julia Sets

Every point on the Mandelbrot image has an associated Julia set. The Mandelbrot is generated by keeping z0 constant (at 0,0) and varying the 'c' term. The Julia sets are generated by keeping 'c' constant and varying z0. The Julia set for a given 'c' value looks similar to the Mandelbrot around the same value of 'c'. This can be seen in these images for the 'c' value of (-0.3006818, 0.6600910). 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.

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









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

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.

 

 

 









This sequence is for 'c' = (-0.55113284371278159, 0.62783963563277212) and progressively zooms in on Z = (0, 0), again in steps 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.505, 0.570).

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.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 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 zooming into the areas where the black circles appear to meet you can find spirals with any (odd) number of spokes you like.

   

Other Sets

The Julia sets can be considered to occupy are an infinite set of planes perpendicular to the plane of the Mandelbrot set. Because we are talking in 4 dimensions these planes only intersect the Mandelbrot plane at a single point. Another infinite collection of planes lie parallel to the Mandelbrot plane. These are accessed by changing the starting value of Z in the iteration but otherwise keeping the calculations the same. This section shows a few examples, some very interesting animations can be seen on the animations page. This image is for quite a large Z0 value (0,1.1), where the familiar Mandelbrot set has pretty much been destroyed. It can be seen towards the end of one of the animations.

There are more Mandelbrot images here.

Visits since June 2008