//to execute ./output //to compile c++ input.cpp -o output -L/usr/X11R6/lib -lX11 #include #include #include #include #include #include #include //////////////////////////////////////////////////////////////////////////////// struct data { int x,y; }d[4714]; void read_data(); void get_graph(); int tot = 0; ///////////////////////////////////////////////////////////////////////////////// GC create_gc(Display* display, Window win, int reverse_video) { GC gc; /* handle of newly created GC. */ unsigned long valuemask = 0; /* which values in 'values' to */ /* check when creating the GC. */ XGCValues values; /* initial values for the GC. */ unsigned int line_width = 1; /* line width for the GC. */ int line_style = LineSolid; /* style for lines drawing and */ int cap_style = CapButt; /* style of the line's edje and */ int join_style = JoinBevel; /* joined lines. */ int screen_num = DefaultScreen(display); gc = XCreateGC(display, win, valuemask, &values); if (gc < 0) { fprintf(stderr, "XCreateGC: \n"); } /* allocate foreground and background colors for this GC. */ if (reverse_video) { XSetForeground(display, gc, WhitePixel(display, screen_num)); XSetBackground(display, gc, BlackPixel(display, screen_num)); } else { XSetForeground(display, gc, BlackPixel(display, screen_num)); XSetBackground(display, gc, WhitePixel(display, screen_num)); } /* define the style of lines that will be drawn using this GC. */ XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style); /* define the fill style for the GC. to be 'solid filling'. */ XSetFillStyle(display, gc, FillSolid); return gc; } GC gc; Colormap screen_colormap; XColor color,exact; unsigned long pixel[3]; char *str[] = {"red","blue","green"}; Display *dsp = XOpenDisplay( NULL ); Window win; int main() { int i,j,mx; ////////////////////////////////////////////////// if( !dsp ) { return 1; } unsigned long valuemask = 0; XGCValues values; int screenNumber = DefaultScreen(dsp); unsigned long white = WhitePixel(dsp,screenNumber); unsigned long black = BlackPixel(dsp,screenNumber); win = XCreateSimpleWindow(dsp,XRootWindow(dsp, screenNumber), 0, 0, 800, 600, 1, BlackPixel(dsp, screenNumber), WhitePixel(dsp, screenNumber)); for(i=0;i<3;i++) { XAllocNamedColor(dsp, DefaultColormap(dsp,screenNumber), str[i], &color, &exact); pixel[i] = color.pixel; } XMapWindow( dsp, win ); long eventMask = StructureNotifyMask; XSelectInput( dsp, win, eventMask ); XEvent evt; do{ XNextEvent( dsp, &evt ); // calls XFlush }while( evt.type != MapNotify ); gc = create_gc(dsp, win, 0); if (gc < 0) { fprintf(stderr, "XCreateGC: \n"); } XSync(dsp, False); ////////////////////////////////////////////////////////////////////////// read_data(); get_graph(); ////////////////////////////////////////////////////////////////////////// eventMask = ButtonPressMask|ButtonReleaseMask; XSelectInput(dsp,win,eventMask); // override prev do { XNextEvent( dsp, &evt ); // calls XFlush() } while( evt.type != ButtonRelease ); XDestroyWindow( dsp, win ); XCloseDisplay( dsp ); return 0; return 0; } void get_graph() { int i; XSetForeground( dsp, gc, pixel[0] ); for(i = 0; i < tot; i++) { // if(cell[i].cell_count > 0) XDrawPoint(dsp,win,gc,d[i].x,d[i].y); } } /////////////////////////Reading data from file//////////////////////////// void read_data() { int i; FILE *fp; printf("\nEnter the File name\n...."); fp = fopen("tridata.txt","r"); if(fp == NULL) { printf("Error in reading."); exit(0); } i = 0; while(fscanf(fp, "%d %d ",&d[i].x,&d[i].y) >= 1) { i++; } tot = i; printf("\nTotal No. of points: %d\n", tot); fclose(fp); }