A Detour into Fractals

This chapter would be incomplete and dry without a small foray into Mandelbrot sets and the implementation of draw_mandel.

For starters, I highly recommend Ivars Peterson’s book The Mathematical Tourist [Section 18.7] for its engaging style and treatment of a surprisingly wide set of mathematical topics. We’ll begin by assuming that you already know about complex numbers.

We know that a complex number a + b i is composed of two parts, the real part a, and the imaginary part b, that taken together constitute a point on a graph. Now consider the expression z = z 2 - 1, where z is a complex number. We start with a complex number (z 0) and plot it. We then substitute it in the above expression to produce a new complex number and plot this number. This exercise is repeated, say, 20 or 30 times. We find that different starting values of z 0 result either in this series trailing off to infinity, or remaining confined within a boundary. All z 0’s that result in a bounded series belong to a Julia set, named after the mathematician Gaston Julia. In other words, if we plot all the z 0’s that result in a bounded series, we will see a nice fractal picture (no, not the one we saw earlier).

Now, let us make the equation a bit more general: z z 2 + c, where c is a complex number (the discussion above was for c = -1 + 0i). Now, if we plot the Julia sets for different values of c, we find that some plots show beautiful connected shapes while other disperse into a cloud of ...

Get Advanced Perl Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.