//Oguz Yetkin //graph.cpp //10/4/1997, Physics 505 #include #include #include #include #include "graph.h" //unfortunately, we're using borland c++ graphics drivers //int init(int &maxx, int &maxy); int init(int &maxx, int &maxy); //internal static struct graphparam{ int maxx; int maxy; float xmin; //user specified float xmax; //user specified float ymin; //user specified float ymax; //user specified int OK; } graph; /* int main(int argc, char** argv){ //int maxx, maxy; //init(maxx, maxy); //printf("\nmaxx: %d, maxy:%d",maxx, maxy); float xmin, xmax, ymin, ymax; float x,y; //dummy cout<<"\nenter xmin xmax ymin ymax"<>xmin>>xmax>>ymin>>ymax; if(graphsetup(xmin, xmax, ymin, ymax)<0){ cout<<"\ngraphsetup failed!"<>x>>y; plot(x,y); } return 0; } */ int init(int &maxx, int &maxy){ //initialize graphics //************************************ int driver=DETECT; int mode; //int maxx, maxy; //will be 640x480 //**************INIT GRAPHICS********************** initgraph(&driver, &mode, "h:\\borlandc\\bgi"); setbkcolor(BLACK); setcolor(WHITE); maxx=getmaxx(); maxy=getmaxy(); return 1; //***************END GRAPHICS INITIALIZATION********************** }//end init void graphclose(){ closegraph(); } //uses global struct graph int graphsetup(float xmin, float xmax, float ymin, float ymax){ if((xmax<=xmin)||(ymax<=ymin)){ cerr<<"\ninvalid parameters"; return -1; }//end if graph.xmin=xmin; graph.ymin=ymin; graph.xmax=xmax; graph.ymax=ymax; init(graph.maxx, graph.maxy); setbkcolor(BLACK); setcolor(WHITE); graph.OK=1; return 1; //now we have all the variables we need from user } //return x resolution in world coordinate units //call AFTER graphsetup!!! float deltax(){ if(graph.OK!=1){ cout<<"\ncan't call deltax() before initializing graphics"<