SOME NOTES ON THE MANDELBROT SET and THE PROGRAM MNDLZOOM Philip A. Seeger 239 Loma del Escolar Los Alamos, NM 87544 (505)662-7163 PASeeger@losalamos.com December 4, 1989 Revised: April 17, 1991 Revised: April 5, 1992 Revised: June 1, 1994 Revised: June 1, 1996 Revised: February 12, 1997 Revised: March 24, 2002 NEW FEATURES: Color-wheel rotation has been revised so it will work with any (?) graphics hardware (but itmay be slower than in the original version). Colors on screen and file match. Directory name remembered between plots. Sizes up to 1600x1200. I. System Requirements A. IBM-PC or clone running the Windows95/98 or WindowsNT operating system. (Will NOT run under Windows 3.1, even if WIN32s is installed.) B. If the processor chip is an 80386 or an 80486SX, a math coprocessor is ABSOLUTELY REQUIRED. (It is built-in in an 80486DX, Pentium, or later.) C. At least VGA graphics card/monitor for 640x480, 16-color, with appropriate Windows drivers installed for whatever higher resolution modes the hardware supports. D. Adequate disk space, preferably on hard disk, for file images (see file sizes below). E. Program modification and recompilation would require Digital/Compaq Visual Fortran 5.0/6.0. II. The Mandelbrot Set Your enjoyment of this program will be greatly enhanced if you read some or all of these references: A. K. Dewdney, Scientific American 253, no. 2 (August, 1985) 16-20. A. K. Dewdney, Scientific American 257, no. 5 (November, 1987) 140-144. B. B. Mandelbrot, Annals NY Academy of Science 357 (1980) 249-259. B. B. Mandelbrot, The Fractal Geometry of Nature (Freeman, New York, 1983). H.-O. Peitgen and P. H. Richter, The Beauty of Fractals (Springer-Verlag, Berlin, 1986). H.-O. Peitgen and D. Saupe, eds., The Science of Fractal Images, (Springer-Verlag, New York, 1988). P. A. Seeger, "Some Notes on the Mandelbrot Set, or What is the Length of the Coastline of Mandelbrot?", Los Alamos National Laboratory report LA-UR-89-1400 (unpublished, 1989). But I must issue a severe warning: if you are attracted to strange shapes which almost seem to have meaning of their own, or if you have any curiosity about systems which seem to go on forever with intriguing self-similarity coupled with infinite variety, or if you have even the slightest knowledge of such things as the complex number plane, rational numbers, countable infinities, etc., the Mandelbrot set may become addictive!!! The Mandelbrot set has been described at the most complicated mathematical structure known to man -- and yet it is derived from a single almost trivial equation! It is defined as the set of all complex numbers c such that iteration of z = z2 + c starting from z = 0 + 0i does not diverge. The philosophy of the MNDLZOOM program is taken from the Scientific American articles and the fascinating book by Peitgen and Richter listed above. The screen is a window into some magnified rectangle in the complex c plane. Pixels corresponding to values of c such that z = z2 + c does not diverge within some maximum number of iterations are set to black, and for points which do diverge colors are assigned according to the number of iterations before the magnitude of z reaches 1000. The higher the magnification, the more iterations are required before the program will assume the point isn't going to diverge. [Technical note. The iterations are performed totally within the coprocessor with 19-significant-figure resolution. This allows a few hundred iterations before floating-point roundoff errors accumulate enough to affect the least bit of an ordinary double-precision number. The execution time of the program is dominated by the time it takes to do each iteration. The machine on which I first ran this program, an 8-MHz 8086/87, performed 4670 iterations per second; a recent 80486DX/2 66-Mhz machine does 490,000 per second. My current Pentium Pro 200-MHz does 8.3 iterations per microsecond, nearly two thousand times faster than 8 years ago!] Three algorithms (all described in "The Science of Fractal Images") are provided for mapping of colors: number of iterations, "escape time" or potential, and azimuth of escaping trajectory. Black always represents the maximum allowed number of iterations, which by default is the smaller of 65534 or 256 times the square root of the magnification, and white may be used to outline the set to show its connectivity. The remaining 234 (or 14, or none if "B/W" is chosen) colors are used cyclically. The palettes are set internally, and go from the green side of yellow through green, cyan, blue, magenta, and red, to yellow. For the number-of-iterations algorithm, the color changes for each iteration, and for azimuth, the range from 0-360 degrees is one cycle (either 234 or 14 colors). The escape-time scale is linear below 4 iterations, quadratic up to 256, and logarithmic above; the first cycle (234 or 14 colors) is from 0 to 82.1 iterations, the second cycle extends to 292.4, the third to 794.7, and the fourth to 2160.3 iterations. The Fortran main program MNDLZOOM.FOR, two assembly language subroutines which do the iterations (MANDELAZ and DISTMNDL, .ASM and .OBJ files), four Windows interface routines (MNDLDBOX.FOR, MNDLHELP.FOR, MNDLMENU.FOR, and MNDLMOUS.FOR), a drawing utility (PIXEL.FOR), and resource-definitions (RESOURCE.H and .FD) are included. The main program includes a subroutine with mathematical expressions for the cardioid for the main body and the circle for the first bud, to avoid having to iterate in those major areas. If you do become involved with the mysteries of the Mandelbrot set, you may wish to translate the programs to your own favorite language and modify them to your own needs. Unfortunately, this version is not very transportable because it is tied so strongly the Microsoft "QuickWin" environment and MS/Digital/Compaq Fortran 4/5/6. This is advertised to be compatible with Microsoft C++, if you account for call-by-reference instead of call-by-value. (As someone who learned Fortran when it was a new-fangled creation to save the tedium of assembly language programming, I have been unable to cope with C or C++. I am very relieved that the new MS Fortran lets me do C-like things without having to deal with C.) A final challenge for addicts: What is the length of the coastline of Mandelbrot? Another question: what does this have to do with neutron scattering? This program was originally written for "research" on the Mandelbrot set, and to stretch the limits of speed and precision of a PC. If you use it for recreational purposes, such as to create wallpaper for your desktop, it is completely free. However, if you really get involved, and find it useful to you to have this program and source code, I request a fee of $25. (If 150 people were to send me the fee, that would about cover my consulting fee for the hours I spent upgrading to Win32.) III. Running the Program The program may be executed by navigating to the directory where file MNDLZOOM.EXE is, and double-clicking it. An alternative is open a DOS Window, transfer to a working directory where you want the resulting images to be stored, and entering [path]MNDLZOOM (where "path" points to the program). The program first opens a dialog box, and you may change the working directory; a log file (MNDLZOOM.TXT) and the output picture file will be written in this directory. Next, choose resolution and number of colors. All modes will be offered, but only modes allowed by your driver will be accepted. The available modes are Mode Width Height Colors File Size V1 640 480 16 153920 V2 640 480 236 308480 S1 800 600 16 240400 S2(default) 800 600 236 481600 X1 1024 768 16 393728 X2 1024 768 236 787456 Z1 1280 1024 16 656000 Z2 1280 1024 236 1312000 h1 1600 1200 16 960800 h2 1600 1200 236 1921600 Note: black-and-white modes (V0, S0, X0, Z0 and H0) are stored as 16-colors. In addition to specifying (or accepting) the center and magnification of each picture, optional colorizing algorithms are offered. Choose "Escape time" equipotentials (default mode), "Integer" number of iterations before reaching radius 1000, or "Azimuth" to color according to the azimuth of the iteration passing radius 1000. In the latter case you may specify the reference angle in integer degrees; this determines which color will be continuous to infinity. The next option is to outline the Mandelbrot set with a white "Border" of specified thickness (in pixels), which makes the invisible network of infinitesimal interconnecting lines visible. However in some cases the white border may hide detail, so try all the combinations. For a brief review of the instructions, click on the "Help" button, or to quit, click "Exit". The "OK" button begins computation. If any entries are out of range, the dialog box will be re-opened with the default entries set to the limits. When the picture is complete the color wheel will begin to rotate. You can freeze the or unfreeze colors by using the "State" menu (Rotate Palette). Whenever the color rotation is stopped, the palette of the output file is updated to match the screen. The bitmapped file is suitable for input to Windows (for example, as wallpaper or as input to Paintbrush or other graphics utilities). File names are MNDLBRTx.BMP, where x is a digit 0-9 or letter A-Z. File format is uncompressed (i.e., not RLE, run-length encoded). To stop the picture and draw a "zoom" box for a new one, use the State menu (Stop/Zoom Picture) or hold the left mouse button. The picture should stop at the end of its current line, and the box should appear in the middle of the screen (or centered on the mouse position), sized for a magnification 10 times higher than the previous picture. You may move the box by dragging or clicking the left mouse button, or resize it with the right mouse button. To return to the dialog box, use the State menu (New Case or Exit). If the previous picture was completed, you have the option not to save it. The defaults for the location and magnification of the next picture are the final location and size of the zoom box. You may enter a new starting point manually; either favorite places you have found for yourself, or additional examples from "The Beauty of Fractals." If you have not encountered the Mandelbrot set before, I recommend starting with the default values of position and magnification. Then take a zoom into "Seahorse Valley"; using (perhaps) magnifications of 25, 150, 1200, 7000, 30000, 6.E5, 1.E7, 2.E8, and 3.E9. Notice the Mandelbrot islands, which look like miniatures of the whole set. If you stay in the vicinity of the built-in starting point, notice that all branch points (eyeballs, wheels, dendroids) have 29 spokes. (Why? How about in other regions?) The starting position included in the program gives interesting pictures at least up to a magnification of 1.E10 -- but you need a lot of patience when the magnification gets large -- if there is much black area, a picture may take (many) hours to complete. Enjoy! - -