Programming and Graphics

(Kiana) #1

7.5 A graph with axes 227


char device[]="X11"; // initialize on the screen
vinit(device);
ortho2 (xmin-xmarg,xmax+xmarg,ymin-ymarg,ymax+ymarg);
color (WHITE);
clear();

//--- Draw markers:

color (BLACK);
int marker = 3;

for(int i=0; i<n; i++)
{
if( xd[i]>xmin && xd[i]<xmax
&& yd[i]>ymin && yd[i]<ymax)
drawmarker2d (xd[i], yd[i], marker
,xmin, xmax,ymin, ymax);
}

//--- Prepare the graph:

color (BLUE);
int Icheck=1;
drawline2d (n,xd,yd,xmin,xmax,ymin,ymax,Icheck);

//--- Draw axes:

drawaxes2d

(xmin,xmax

,ymin,ymax
,ntcx,ntcy
,Ilabelax // 1 to label axes; 0 for no labels
,axc // axis color
,lbc // label color
,labelx // x-axis label
,labely // y-axis label
,title1 // first title
,title2 // second title
,title3 // third title
);

//--- Wait to finish:

char kbd = char(getkey());

return 0;
}
Free download pdf