Fractals drawn with Java AWT

This program, fract.java, uses Java's AWT to draw some of the best known fractals, Julia sets and the Mandelbrot set. The examples I mention below, plus some other pretty pictures, can be produced automatically by selecting from a pull-down-menu in the control frame. If you've got a fast computer, stretch the graphics window and you'll see much more detail.

        Julia sets are named after their discoverer, Gaston Julia, who was sadly French and had no nose (it was shot off by Germans during the first world war). The Mandelbrot set is named after their discoverer, Benoit Mandelbrot, who is from a country near Germany, and has a nose. Coincidence? I don't think so.

        Anyway, this is the idea behind a Julia set: Take any two numbers, Z and C, and perform the calculation Z=Z2+C repeatedly. If Z and C are at all large, the calculation will shoot off towards infinity pretty quickly (such as starting with Z=4, C=1, when the results give the ever increasing sequence 4, 17, 290, 8401, ..., so it is worth noting that 4 is distinctly large in this context), in which case Z is said to be in the "escape" set for C.
        If the values of Z and C are small enough, the result will settle down, either to a single value (such as starting with Z=-1, C=-2, when the result is always -1), or into an orbit that cycles through a number of values (such as starting with Z=0, C=-1, when the result alternates between 0 and -1), in which cases Z is said to be in the "prisoner" set for C.
        At some point, when the values of Z and C are not particularly large, and not particularly small, it is hard to predict whether a value is in the escape set or the prisoner set. This infinitesimally thin interface between the prisoner set and the escape set is the Julia set.
        For normal numbers, the Julia set isn't at all spectacular, and would not have become famous, but if Z and C are allowed to be complex numbers, things are very different.
        For any particular Julia set, a value of C is chosen and remains constant. Small differences in the chosen value of C result in very different pictures. Then, a range of values for Z is selected, and each value in that range is tested. The test is to repeat the calculation Z=Z2+C many times and note whether it runs off to infinity or settles down. The colour of the pixel at Z's position is chosen to represent the number of steps it took for the calculation to become almost infinite (i.e. 4).
        The main inputs to the algorithm are the value of C, both its real and imaginary parts, and the range of values for Z (both parts). Once a nice value of C is found, you "zoom in" on interesting parts by narrowing down the range of Z. The pixel corresponding to a value of Z is found in the natural way: the real component is along the horizontal axis, and the imaginary one vertical, so if you selected -2...+2 as the range for Z's real part, and -1...+1 as the range for Z's imaginary part, Z=0+0i is right at the middle of the screen, Z=2+1i is in one of the corners, and Z=-1-0.5i is half way between the centre and the opposite corner. The program refers to Z's real part as X, and its imaginary part as Y.
        You zoom in either by typing a new range for X and Y, or by dragging the mouse across an interesting region on the picture, then pressing "do it now". As you get deeper into a picture, detail starts to be lost fairly quickly. This is because the program can't really test every value of Z to see if it shoots off to infinity, some values may remain nice and stable for a thousand or even a million repetitions of the loop, and only then start to grow large. For these values, the program uses a threshold value (called MaxTimes); if a value of Z still hasn't become infinite after MaxTimes runs of the loop, the program assumes that it never will. For large overviews with ranges like -2...+2, that works perfectly well, but when zoomed in, it doesn't. When you zoom in, if the picture doesn't look very sharp, or has too many big white areas, increase the value of MaxTimes and redraw. The picture will take longer, but be sharper. MaxTimes can be increased to a couple of thousand without problems, but you'll want a fast computer. Also, just changing the colour scheme can sometimes make things a lot clearer.

Some interesting Julia sets:
No.C(real)C(imag)XminXmaxYminYmax
10.00.0-2+2-2+2A boring circle
2+0.30.0-2+2-2+2A jellyfish
3+0.30.00.360.58-0.33-0.13Detail of jellyfish (MaxTimes 75)
4-0.750.0-2+2-2+2The "San Marco" fractal.
Zoom in on the little men to see the infinite self-similarity
5-1.450.0-2+2-2+2Interesting spikes.
6-1.450.0+1.1+1.3-0.13+0.07A pretty detail of the spikes.
70.0+0.6-1.5+1.5-1.5+1.5Jagged Island
80.0+0.69-1.5+1.5-1.5+1.5Swirly Galaxies
90.0+0.75-1.5+1.5-1.5+1.5Chinese Dragons
100.0+0.84-1.5+1.5-1.5+1.5Lightning
11-0.7+0.35-1.5+1.5-1.5+1.5Snowflakes
12-0.7+0.31-1.5+1.5-1.5+1.5Flowers (a lot of detail to zoom in on)

An interesting thing that Julia discovered was that all these sets are either completely connected in one big continent (like numbers 1 and 7 in the table) or form a truly infinite splattering of islands (like numbers 8 and 12); there is no compromise, you can never find just two separate islands.
        It was in investigating this that the Mandelbrot set was discovered. The idea is that Julia sets are completely defined by the value of C that is chosen; C is a complex number that could be mapped into pixels just as Z is for the Julia set. A point C is in the Mandelbrot set if the Julia set based on C consists of just one big continent. Surprisingly, the Mandelbrot set can be computed in almost exactly the same way as the Julia sets: For each value of C, start with Z=0, and repeatedly compute Z=Z2+C. If it goes off to infinity, then C is not in the Mandelbrot set. Strictly speaking there is only one Mandelbrot set, which is what the program produces if you set C(real) and C(imag) to zero. These inputs provide the starting point Z=0. However, by playing around with different starting values, you can produce some other interesting pictures.
        The interesting thing about the Mandelbrot set is the enormous variety of self-similar regions it contains. With C(real) and C(imag) both zero, look at:
No.XminXmaxYminYmaxMaxTimes
1-2.2+0.8-1.5+1.550The whole thing
2-0.33+0.09-1.03-0.6570No. 1's upper arm
3-0.111-0.099-0.930-0.920150Floating above No. 2's head
4-0.1039-0.1028-0.9246-0.9235350No. 3's arm
5-0.103072-0.102996-0.924157-0.924095500Hidden in No. 4's longer antler
You can go on zooming in on smaller and smaller Buddhas for ever (except for the limits given by your computer's hardware. Notice that the scale of picture number 5 is about 200,000 times smaller than the scale of picture number 1. The program uses double precision floating points numbers, but even they run out annoyingly soon.