/* fractal.c - Sample Mandelbrot Fractal Display Starting code for CSE 30341 Project 3. */ #include "gfx.h" #include #include #include #include #include #include /* Compute the number of iterations at point x, y in the complex space, up to a maximum of maxiter. Return the number of iterations at that point. This example computes the Mandelbrot fractal: z = z^2 + alpha Where z is initially zero, and alpha is the location x + iy in the complex plane. Note that we are using the "complex" numeric type in C, which has the special functions cabs() and cpow() to compute the absolute values and powers of complex values. */ static int compute_point( double x, double y, int max ) { double complex z = 0; double complex alpha = x + I*y; int iter = 0; while( cabs(z)<4 && iter < max ) { z = cpow(z,2) + alpha; iter++; } return iter; } /* Compute an entire image, writing each point to the given bitmap. Scale the image to the range (xmin-xmax,ymin-ymax). */ void compute_image( double xmin, double xmax, double ymin, double ymax, int maxiter ) { int i,j; int width = gfx_xsize(); int height = gfx_ysize(); // For every pixel i,j, in the image... for(j=0;j