/************************************* * * * Some skeletal graphics commands * * J. Mallinckrodt, Oct. 1999 * * * ************************************/ // Header files #include // Prototypes int initialize_graphics(void); // Go into graphics mode void setup_graphics(void) // Set up graphics variables void plot(void); // Do the plotting int xscr(float x); // x screen conversion int yscr(float y); // y screen conversion // Global variables int maxx,maxy; // Set by initialize_graphics int xminscr,xrangescr,yminscr,yrangescr; // Pixel range values float xmin,xrange,ymin,yrange; // Physical range values float x_old,y_old,x_new,y_new // Physical values to plot int main(void) // Start of main routine { ... initialize_graphics(); setup_graphics(); ... outtextxy(0,140,"Press any key"); outtextxy(0,150," to exit"); getch(); closegraph(); } // End of main routine // Functions /****************************************************************/ int initialize_graphics(void) { int graphdriver=DETECT,graphmode,error_code; // Local variable declarations // The primary graphics init call initgraph(&graphdriver,&graphmode,"c:/tc3/bgi"); error_code=graphresult(); // Set error code //See if there were any problems if(error_code != grOk) // and if so ... return -1; // ... set error return value // See if an EGA or VGA graphics // driver was found and if not ... if ((graphdriver != EGA) && (graphdriver != VGA)) { closegraph(); // ... close graphics return 0; // ... and return error code } maxx=getmaxx(), // Otherwise set screen size maxy=getmaxy(); return 1; // and return "O.K." } /****************************************************************/ void setup_graphics(void) { xminscr= ... ; // Minimum horizontal pixel xrangescr= ...; // Horizontal pixel range xmin= ...; // Minimum physical "x" value xrange= ...; // Range of physical "x" values yminscr= ...; // Minimum vertical pixel yrangescr= ...; // Vertical pixel range ymin= ...; // Minimum physical "y" value yrange= ...; // Range of physical "y" values // Plus any other graphics commands to draw and label axes, // print titles or legends, etc. E.g., setcolor(15) sprintf(text,"T = %5.2f",T); outtextxy(90,60,text); } /****************************************************************/ void plot(void) { setcolor(plotcolor); line(xscr(x_old),yscr(y_old),xscr(x_new),yscr(y_new)); // or putpixel(xscr(x_new),yscr(y_new),plotcolor); } /****************************************************************/ int xscr(float x) { return xminscr + xrangescr * (x-xmin)/xrange; } /****************************************************************/ int yscr(float y) { return yminscr - yrangescr * (y-ymin)/yrange; }