Interactive Mandelbrot Images
The defined assignment was to create a Mandelbrot image from a user-specified
initial X and Y, delta X and delta Y, and desired image resolution.
Although the actual routines are written in C, a web front-end was created
(this page) to allow world-wide usage of this exploratory program.
The pseudo-code was quickly incorporated as comments into the actual C
code, as shown in the Code Archive.
The code archive includes:
- mand.c: the main routine
- read_mand_args.c: reads command-line options given, if any
- check_mand_params.c: checks all options and parameters, and prompts
for any not specified or out of limit
- check_julia_params.c: if a Julia set is being made, checks Julia-specific
parameters and prompts for any not specified
- m_point.c: the Mandelbrot (or Julia) equation for a single point,
called by mand.c
- z_point.c: several subroutines of alternative pseudo-Mandelbrot routines,
called by mand.c
- dumpimage.c: writes out the image array as a pgm-format file for plotting
- complex.c: various functions for manipulating complex numbers
- complex.h: defines the complex number structure
- display_limits.h: sets absolute limits on image size and number of colors
- mandelbrot_globals.h: defines limits and best values for Mandelbrot figures
- my_environment.h: sets debugging, level of interactivity, and noisiness flags
- makefile: builds the executable 'mandelbrot'
The Mandelbrot equation is defined as z = z^2 + C
where "C" is initially the coordinate in the complex plane and z(0) is C.
A Julia set is defined using the same equation, but in this case C is the
coordinate in the complex plane. Thus the Mandelbrot set is a set of
Julia point solutions. Julia sets outside of the Mandelbrot are dark,
and the most interesting behavior occurs near the borders of the Mandelbrot
figure.
The following sets were created:
Mandelbrot set
(color and pseudo-color) at several zoom levels:
- Figure 1: The Mandelbrot set over the range [-2 2]
- Figure 2: Mandelbrot zoomed in by a factor of ten, into (-0.75, 0.05)
- Figure 3: Mandelbrot zoomed in by a factor of one hundred, into (-0.75, 0.10), with
a maximum iteration level of 10,000 (to see if resolution between colors is
improved over the previous image.)
- Figure 4: Mandelbrot zoomed by a factor of 400 into an interesting site at (0.2725, 0.0125).
Julia sets for several locations were
also made.
- Figure A: Julia set around (-1.245, -0.0816)
- Figure B: Exciting Julia set around (-0.5, -0.5)
- Figure C: Another Exciting Julia set around (-0.75, 0.10)
- Figure D: An interesting symmetric Julia set around (0.275, 0.0)
- Figure E: A bowtie Julia set around (-0.9, 0.0)
- Figure F: Similar Julia set moved slightly, to around (-0.92, -0.28)
- Figure G: Another similar Julia set around (-0.9, -0.7)
- Figure H: "Dead" Julia set around (0.0, 0.0)-- degenerate case.
Alternative pseudo-Mandelbrot sets for
different equation forms were made.
Several variant equations were attempted. Forms of "z = exp(z) + C" and
"z = z*exp(z)" simply produced circles and showed no iterative behavior.
Two interesting variants are shown: "z = z(z+C)" and "z = z(1-z)".
- Figure I: Alternate set, using the equation "z= z(z+c)"
- Figure II: Zoom into the "z= z(z+c)" set by a factor of 10, around (-0.3, -0.5)
- Figure III: Alternate set, using the equation "z= z(1-z)"
- Figure IV: Zoom into the "z= z(1-z)" set by a factor of 10, around (0,0).
- Figure V: Zoom into the "z= z(1-z)" set by a factor of 100, around (0,0).
You can Generate your Own
using a cgibin/Perl
interface to this mandelbrot routine.
This uses the CSI 761 code to generate Mandelbrot sets for user-
provided parameters. The coloring routine is a simple quantizing of
the final image to 256 colors.
The current parameter limits are: x and y must be in the range of [-2,2]
and the image must be 2048x2048 pixels or smaller. Note that higher
definitions (number of pixels) increase the calculation time significantly,
while changing the region limits doesn't affect calculation time.
The plotting was done in two fashions. The interactive program uses the
pbmplus suite (specifically, pgmtoppm, ppmquant (to quantize colors), ad
ppmtogif (to make GIFs). This allows quick interactive generation of GIFs.
The grayscale images are converted to a pseudo-color image by mapping high
iterations to black and low iterations to red. The full color plots were
done using Matlab with the 'jet' colormap. Matlab uses an odd scaling
flip when plotting, such that the axis often become swapped. This leads
to odd alignment problems when matching a zoomed section against the
entire figure (since the orientation may have shifted). However, it is
more colorful and has more axis and title options. Therefore, we use
the pbmplus images for interactive plotting, and the Matlab ones for
final "proofs". One could play with colormaps and scaling for days.
As the archive pictures show,
the different scalings of the colormaps cause different features to be
highlighted. This is most noticeable in the zoomed Mandelbrot images,
where a low end compression highlights the differences between the points
outside the set (few iterations before solved before the exit condition is
met) while compressing the high end (near out maximum number of iterations,
in these cases 1000) causes other features to be shown. The visualization
is therefore crucial.
Additional Resources
Bad programmers can learn all they need from the following Obfuscated C
entry, "A mandelbrot plotter".
main(c){float t,x,y,b=-2,a=b;for(;b-=a>2?.1/(a=-2):0,b<2;putchar(30+c),a+=.0503)
for(x=y=c=0;++c<90&x*x+y*y<4;y=2*x*y+b,x=t)t=x*x-y*y+a;}
This plots a mandelbrot using characters. It requires that the terminal it prints to wraps after 80 chars.
A more useful resource (and better online plotters than mine!) are
available at a number of sites, of which
Zsolt's page
(http://chem.leeds.ac.uk/ICAMS/people/zsolt/mandel.html)
is one of the more complete.
Finally,
an archive
of this code, postscript plots, and this document
(in postscript) are available off this page, for people that prefer
hardcopy.