/*********************************************** * Mand3DintGen2.c * * Generates a RAW format file of a 3D image * of Mandelbrot set (grayscale) * * C source file by Alberto Strumia * ************************************************/ #include /* definition of constants */ #define Radius 10 #define Side 0.05 #define Cx 1.24 - 2.0*Side #define Cy 1.3*Side #define M 700 #define Num 255 #define co 1.41 #define si 1.41 /* main program */ main() { int p, q, n, wext, wint, r[M]; double x, y, xx, yy, Incx, Incy, md; FILE *fp; fp = fopen("Mand.raw","w"); for (p = 1; p <= M; p++) { printf("%i %%\n", p*100/M); for (q = 1; q <= M; q++) { Incx = Cx - Side + 2*Side*(p*co+q*si/2)/M; Incy = Cy - Side + 2*Side*(-p*si+q*co/2)/M; x = 0; y = 0; for ( n = 1; n <= Num; ++n) { xx = (x*x - y*y)*(x*x - y*y) - 4*x*x*y*y - Incx; yy = 4*x*y*(x*x - y*y) - Incy; x = xx; y = yy; md = x*x + y*y; wint = md*6000; wext = wint; r[q] = wint; if ( md > Radius ) { wext = n; n = Num; } } r[q] = wext; } for ( q = 1; q <= M; q++) { fprintf(fp, "%c", r[q] ); } } fclose(fp); } /* end of main program */