#include #include #include #define XSIZE 2560 #define YSIZE 2048 #define MAXITER 255 double xleft=-2.01; double xright=1; double yupper,ylower; double ycenter=1e-6; double step; int pixel[XSIZE*YSIZE]; #define PIXEL(i,j) ((i)+(j)*XSIZE) typedef struct { double real,imag; } complex_t; void calculate() { for(int i=0;i>8)&255,(size>>16)&255,size>>24,0, 0,0,0,54,0,0,0,40,0,0,0,x&255,x>>8,0,0,y&255,y>>8,0,0,1,0,24,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; fwrite(header,1,54,f); fwrite(buffer,1,XSIZE*YSIZE*3,f); fclose(f); } /* given iteration number, set a colour */ void fancycolour(uchar *p,int iter) { if(iter==MAXITER); else if(iter<8) { p[0]=128+iter*16; p[1]=p[2]=0; } else if(iter<24) { p[0]=255; p[1]=p[2]=(iter-8)*16; } else if(iter<160) { p[0]=p[1]=255-(iter-24)*2; p[2]=255; } else { p[0]=p[1]=(iter-160)*2; p[2]=255-(iter-160)*2; } } int main(int argc,char **argv) { if(argc==1) { puts("Usage: MANDEL n"); puts("n decides whether image should be written to disk (1=yes, 0=no)"); return 0; } /* Calculate the range in the y-axis such that we preserve the aspect ratio */ step=(xright-xleft)/XSIZE; yupper=ycenter+(step*YSIZE)/2; ylower=ycenter-(step*YSIZE)/2; calculate(); if(strtol(argv[1],NULL,10)!=0) { /* create nice image from iteration counts. take care to create it upside down (bmp format) */ unsigned char *buffer=calloc(XSIZE*YSIZE*3,1); for(int i=0;i