/* Simple program to plot the Mandelbrot function. Works on an nXn pixel array, mapped to be centered at the complex coordinate (c0r, c0i), with radius r. Calculates for each pixel a positive integer <= lim indicating the number of iterations required for the function to diverge (if it does). n, c0, r, and lim can be set by command-line arguments. If -p is specified on the command line, the program outputs the final array as a pgm (portable grey map) image, readable/displayable by the Unix xv program. compile with cc -O -o mandel mandel.c -lm */ #include #include #include /* the following line is Mac CodeWarrior specific */ /* #include */ long n = 512; /* number of pixels on a side */ double c0r = 0.37; /* real component of center */ double c0i = 0.1; /* imaginary component of center */ double r = 0.005; /* radius */ long lim = 60; /* divergence threshold */ int print = 0; /* boolean; print result? */ double distance(double x, double y) { return sqrt(x*x+y*y); } void mandel(long *ans, long n, double c0r, double c0i, double r, long lim) { double dx=r/(n-1), dy=r/(n-1), zr, zi, tmp, cr, ci; long i,j,k; for (i=0; i