Fun with fractals
Mike Bedford leads us on a voyage of discovery into the maths of fractals and the extraordinary geometrical figure known as the Mandelbrot Set.
Mike Bedford leads us on a voyage of discovery into the maths of fractals and explores the extraordinary geometrical figure known as the Mandelbrot Set.
Prepare to be amazed! In this tutorial, and in next issue’s follow up, we’re going to be looking at fractals, a subject that is both visually and technically astonishing. Typically at this point we’d start by explaining what we mean by the word fractal. However, that can wait until later. Just let’s start by whetting your appetite, because this is such a fascinating and eye-catching subject that we don’t want to get bogged down in the nitty gritty at such an early stage.
Instead, there can be no better introduction to incredible world of fractals than by taking a look at the Mandelbrot Set, which is surely the most well-known fractal. Even if you’re already familiar with this bizarre graphical image, though, perhaps you’ll excuse our visual and hyperbole-rich introduction to fractals. Unless you consider yourself a fractal guru, we trust that there wil be plenty here that you’ll find every bit as awe-inspiring as the Mandelbrot Set was when you first encountered it.
Exploring infinity
So what is the Mandelbrot Set? Undoubtedly the best way of finding out is to take a look, so install Fraqtive on your PC (https://fraqtive.mimec.org), fire it up and you’ll be greeted with an image of the Mandelbrot Set. OK, so it’s an unusual image, being somewhere between a regular geometric figure and something a whole lot more random, but at first sight you might not feel that it lives up to the hype we used to introduce it. However, first impressions can be deceptive, as we’re about to see. Like most fractal software, Fraqtive enables you to zoom in so you can see the image in more detail, just as you would in a photo-manipulation package. So try zooming in on an area of the Mandelbrot Set by clicking and dragging, and panning by holding down Shift while doing the same.
We suggest you zoom in on an area about a quarter of the width and a quarter of the height of the entire image. Avoid areas that include only the black part in the centre or only the area toward the edges – coloured in shades of orange – because there’s nothing interesting to see there. If you do accidentally zoom in on a boring area, just reduce the Zoom Factor in the toolbar to the right and try again. Perhaps one of the best places to start zooming is on one of the intricate tree-like structures, perhaps the Y-shaped one near the top, just right of centre. When you’ve zoomed in once, zoom in again, and again, and again.
So long as you continue to pick interesting areas – ones that include the perimeter of the black area – you’ll see more and more weird, yet strangely attractive patterns. These patterns include starbursts, pinwheels, spirals, and delicate branching structures, and although you’ll see similar patterns at each level of magnification, you’ll continue to see something new. Astonishingly, this goes on forever: the Mandelbrot contains infinite detail. Some software might get to a point where it cannot show any more detail, but in that case it’s an implementation issue, not a property of the Mandelbrot Set itself.
An implication of this infinite nature is that you soon get to a point where you’re seeing something that, in all probability, nobody has ever seen before. Surprised at that assertion? Well, let’s do some simple calculations. If you zoom in each time, to an area a quarter or the width and height, that’s a sixteenth of the area. So, after 10 zooms, you’re seeing a billionth of the Mandelbrot Set – and after another ten you’re down to a billion billionth. If everyone on Earth was to start zooming in on the Mandelbrot Set, over and over again, at one zoom per second to 20 zooms, it would be 10 million years, on average, before two people were to see the same area at that 20 zoom limit.
Wha’choo talkin’ ‘bout, Willis?
We’ve now seen something of the extraordinary nature of the Mandelbrot Set, and we know it’s a fractal, but it’s time to shed some light on what we mean, more generally, when we talk about fractals. A nonmathematical definition of a fractal is on the lines of “a geometric figure than displays self-similarity at all levels of magnification”. Indeed, this is what we saw when we looked at the Mandelbrot Set. In the fractals we’re looking at this issues, that similarity is approximate, although with other types of fractals, as we’ll see in the follow-up article, it’s exact. So with the visual introduction out of the way, it’s time to turn our attention to the underlying maths. Don’t let that put you off, though, as this is fairly easy going, and it sheds some light on another extraordinary property of the Mandelbrot Set.
Although the maths aren’t difficult, we are going to refer to complex numbers, so if the concept of imaginary and complex numbers is little more than a hazy recollection from school maths lessons, take a look at the box (above right) before continuing.
Drawing the Mandelbrot Set involves doing a test on values on the complex plane. Start with the value zero, square it and add the complex number being tested. If the modulus of the complex result (which is defined as the distance from the origin of the complex plane) is more than a threshold of two, then the point isn’t in the Mandelbrot Set. If the modulus of the result is less than two, perform the same operation again: square the result and add the value being tested. Once again, if the modulus of the result is greater than two then the point isn’t in the Mandelbrot Set; if it’s less than two, perform the operation again.
For some points, the result will never get far from the origin, no matter how many times this operation is carried out – these are the points in the Mandelbrot Set. For points not in the Mandelbrot Set, however, the modulus will become large after a few iterations, eventually heading off towards infinity.
It isn’t possible to carry out this operation an infinite number of times, so some arbitrary limit on the number of operations has to be imposed – commonly a couple of hundred. In this case, points are considered to be in the Mandelbrot Set if the threshold value hasn’t been reached before the limit on the number of iterations is reached. In reality, all points are either in the Mandelbrot Set or they aren’t, so a picture of the Mandelbrot set could be drawn in black and white. Most software uses colours, however, primarily to make it look more attractive. Black is usually used to denote the
Mandelbrot Set, while a whole range of other colours are used for points not in the Mandelbrot Set. The colour represents the number of iterations that had to be performed before the modulus of the result exceeded that value of two.
Even if you haven’t got your head around this yet – and you will do pretty soon if you start writing your own code – one thing is abundantly clear. The maths isn’t complicated, in fact it’s trivially simple. The only arithmetic operations required are squaring and adding complex numbers, a fact that surely adds to the astonishment. Indeed, you may well ask how such simple arithmetic can produce a geometrical figure that is complex, unpredictable and infinite. Indeed, if we were to query whether God is a mathematician, we wouldn’t be the first to ask such a question, prompted by this and similar fractal images.
If you fancy writing some software to draw the Mandelbrot Set, it’s a highly recommended exercise and it really isn’t too difficult, even for novice programmers. The user interface required to allow zooming and panning is quite a bit more involved, but the basics are pretty simple. To start, therefore, we suggest that you limit the user interface to some means of specifying the portion of the complex plane to plot, or even just draw the Mandelbrot in its entirety first of all, by plotting the area bounded at the top-left by -2 + 1.2i , and at the bottom right by 0.5 – 1.2i. The complex arithmetic you need to perform can be expressed as zn+1 = zn2 + c,
where z is the running total that starts from a value of zero, the subscript indicates the number of iterations, and c is the complex number being tested. Many languages now support complex variables and complex arithmetic, and will probably also provide a modulus function.
Even if you’re using a language that only supports integers and real numbers, though, it’s still not at all difficult. Since a complex number is equal to the sum of a real and an imaginary component, which we can show as re + im i, we can handle it as the two real numbers re and im. The square of re + im i equals re2 + im2 i2+ 2 re im. If we now remember that squaring i gives a value of -1, this simplifies to a complex number with a real component of re2 - im2 and an imaginary component of 2 re im.
Adding two complex number is even easier: just add the two real components together to give the real component, and add the two imaginary components to give the imaginary components The only other bit of complex arithmetic you need to do is to calculate the modulus and, again, this is trivial. Using Pythagoras’ Theorem, the modulus of a complex number is the square root of re2 + im2.
General escape time fractals
Although there are completely different types of fractals, the Mandelbrot Set is of a type known as an escape time fractal. The term ‘escape time’ refers to the fact that the test which defines these fractals involves determining whether or not points escape from the vicinity of the origin of the complex plane, after repeated iterations of some operation. The Mandelbrot Set and the closely related Julia Sets were the first such fractals to be discovered, no doubt because the formula is so simple, but there are countless others.
You can explore some of these in Fraqtive, although most are fairly closely related to the Mandelbrot Set, and you’ll find that many, but not all, share something of the standard Mandelbrot Set’s characteristic nature. If you want to delve further into escape time fractals, there’s a wealth of software available that allows you to venture a bit further from familiar territory. A good one to try is Xaos (http://matek.hu/xaos/doku.php). We could have used this for our visual introduction to the Mandelbrot Set, because it does pretty much all that
Fraqtive does while adding extra fractals, but we decided to feature both to give you a better feel for the range of fractal software available.
Like nearly all fractal software, Xaos shows the Mandelbrot Set when it first starts up. To select a different fractal, go to Fractal > Formulae, which lists several more that you can choose from. Not all are escape time fractals – a few are very different types of fractals that we’ll look at next month – but some escape times fractals that are visually quite unlike the Mandelbrot Set include Newton, Octal, Phoenix and Magnet, plus some others under Fractal > More formulae. Note also that most of these formulae have both a Mandelbrot and a Julia variant (we’ll leave you to read up on the difference) that you can toggle between using the M key. There are lots of Julia Sets associated with one Mandelbrot Set, and which one you get depends on where the pointer is when you press M. There’s even a facility for entering your own formula at Fractals > User formula.
Creating your own fractal software offers you the maximum opportunity to explore the wider world of escape time fractals. However, in this instance, we suggest that you first read up on which types of functions others have found interesting, as this could save you countless hours of fruitless experimentation.
You might just have noticed that Fraqtive has the option of 3D View. This just shows the usual twodimensional Mandelbrot Set as a sort of landscape, in which the Mandelbrot Set itself is a deep chasm, the surrounding areas far from it forms a plateau, and the perimeter of the Mandelbrot Set appears as a steep cliff dropping into the abyss. It does prompt the question, though, as to whether there genuinely is such a thing as a 3D escape time fractal.
It transpires that the answer is yes, as you can see if you take a look at another piece of fractal software called Mandelbulber (www.mandelbulber.com). We’ll leave you to find your way around this software – there’s a lot more to it than Fraqtive or Xaos – but to start, just click Render from the opening page and you’ll see the default 3D fractal appear.
Fractal art
Escape time fractals might be visually attractive, in a way that’s reminiscent of ’60s psychedelic art, but can an image that’s generated mathematically actually be considered art? The fact that you can buy posters featuring deep zooms of the Mandelbrot set, produced by people who call themselves fractal artists, might suggest so. But if the process of generating that image involves nothing more than zooming into a fractal until you see something you like, that might be questionable.
Given that, for many, the appeal of fractals is largely visual, this is a question of which we were keen to get to the bottom. To understand better whether the artistic temperament and the mathematical nature of fractals fit comfortably together, we spoke to programmer David Makin, who refers to himself as a fractal artist. He was a winner of the International Benoit Mandelbrot Fractal Art contest in 2006, and sells his work at www.fractalgallery.co.uk. We asked how he can reconcile the artistic tag being used to describe the results of applying a mathematical formula.
“To answer the question ‘Can fractal images be art?’, we first have to define exactly what is meant by the question itself”, he suggested. “Even the fine art community will argue among themselves about the definition of art and has been doing so probably for centuries. In the base sense, personally, I think anything created to be seen by others as art is in fact art, and to an individual, anything they see as art is art.”
Here David drew a comparison with photography. “I’m going to compare the production of fractal images using a computer program with the art of photography. Landscape photographers may not know exactly what they want until they see it, so they may move around a location to find the appropriate view that they wish to capture. The equivalent in fractal art involves using fractal software to explore the virtual landscape of the fractals themselves by panning, zooming, rotating and so on.
“This is followed usually by the equivalent of choosing the lighting conditions and ‘dressing the set’. Although the raw fractal shape is invariant at this stage, modern fractal software allows a myriad of choices for ways of colouring the image. This involves not just the colours that are used and their rate of change, but also the way the colours change independently of the raw fractal shape. Modern fractal software allows hundreds of choices of colouring methods, most of which allow for fine tuning to the artist’s requirements.”
What’s more, all of this can get very mathematical, especially for those who are prepared to hack their own fractal code, as David explained. “These can be almost any mathematical or algorithmic construction that can be conceived, and use some or all of the mathematical data generated during the calculation of the fractal for
each point in the image. One colouring method is generally used for points inside the fractal and another for outside.”
David also sees similarities between fractal software and the tools used by photographers for postprocessing. “More sophisticated fractal software allows multi-layering in the same way as Photoshop and other digital photo manipulation packages. With fractal software each layer could potentially use a different raw fractal, but often fractal artists just combine layers that have the same raw fractal shape but have different choices of colouring applied to each layer.” And all of this is just a start; according to David, the sky’s the limit for the creative fractal artist.