/* compile : gcc -L/usr/X11R6/lib -lX11 xmandelbrot.c -o xmandelbrot */ #include #include #include #include #define WIDTH 256 #define HEIGHT 256 #define NMAX 1000 #define NCOL_R 8 #define NCOL_G 8 #define NCOL_B 8 #define JULIASET int main(int argc, char **argv); void setcolorcell (void); void draw_graph (void); int recurs (double, double); Display *dp; Window wp; GC *gcp; double xmin, xmax, ymin, ymax; #ifdef JULIASET double creal, cimag; #endif int main(int argc, char **argv) { XEvent event; XSetWindowAttributes ap; if(argc<5){ printf("xmandelbrot xmin xmax ymin ymax\n"); exit(0); } xmin = atof(argv[1]); xmax = atof(argv[2]); ymin = atof(argv[3]); ymax = atof(argv[4]); #ifdef JULIASET creal = atof(argv[5]); cimag = atof(argv[6]); #endif if ((gcp=(GC *)malloc(sizeof(GC *)*NCOL_R*NCOL_G*NCOL_B))==NULL){exit(-1);} dp = XOpenDisplay(NULL); wp = XCreateSimpleWindow(dp,RootWindow(dp,0),0,0,WIDTH,HEIGHT,1,WhitePixel(dp,0),BlackPixel(dp,0)); ap.backing_store=Always; XChangeWindowAttributes(dp,wp,CWBackingStore,&ap); XSelectInput(dp,wp,ButtonPressMask|ButtonReleaseMask); setcolorcell(); XMapWindow(dp,wp); XFlush(dp); draw_graph(); while(True){ XNextEvent(dp, &event); if(event.type == ButtonPress) break; } return 0; } void setcolorcell() { XColor col; int i,j,k,n,di,dj,dk; di = 0xffff/NCOL_R; dj = 0xffff/NCOL_G; dk = 0xffff/NCOL_B; col.red =0; col.blue =0; col.green=0; gcp[0] = XCreateGC(dp,wp,0,NULL); XAllocColor(dp,DefaultColormap(dp,0),&col); XSetForeground(dp,gcp[0],col.pixel); n=0; for(i=0;i2.0 ) break; zr = tr; zi = ti; } return(n); }