2024年4月10日发(作者:)

1

•初始化图形系统

函数名:

ini tgraph

功能:初始化图形系统

用 法:

void far initgraph(int far *graphdriver, int far *grciphmode, char far

*pathtodriver);

程序例:

^include

★include

^include #includo int main(void)

{

/* request auto detection */

int gdriver = DETEC1 gmode, errorcode;

/* initialize graphics mode */

initgraph(&gdriver, &gmode,

"“);

/* read result of initialization */

errorcode

graphresult():

if (errorcode != grOk) /* an error occurred */

(

prin tf (''Graphics error: %sn: grapherrormsg (errorcode)):

printf("Press any key to halt:"):

getch ();

exi t(1); /* return wi th error code */

/* draw a line */

line(0, 0, gctmaxx0, gctmaxy());

/* clean up */

getch ();

closegraph ();

return 0;

2.

函数名:

drawpoly

功能:

画多边形

用法:

void far drawpoly(int numpoints, int far *polypoints);

程序例:

#include

graphics・ h>

★include

^include

#include irH main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode; int maxx, mcixy;

/* our polygon array */

int polyL1OJ;

/* initialhe graphics and local variables */

initgraph(&gdriver, &gmode,;

/* read result of initialization */ errorcode = graphresult();

if (errorcode != grOk)

/* an error occurred */

{

printf(^Graphics error: %sn", grapherrormsg(orrorcode));

prin

("Press any key to halt/); getch ();

/

terminate with an error code */ exi t (1);

}

meixx = getmeixx ();

mcixy = getmcixy 0 ;

poly[0] = 20;

poly[1] = maxy / 2;

/* 1st vertext */

poly[2] = maxx - 20; /* 2nd */ poly[3] = 20;

poly [4] = maxx - 50; /* 3rd */ poly [5] = maxy - 20;

poly[6] = maxx /

2;

poly[7] = maxy / 2;

/*

/* 4th */

drawpoly doesn't automatically close the polygon, so we close il・

poly [8] = poly[0]:

poly[9] = poly[l]:

/* draw the polygon */ drawpoly(5, poly);

/* clean up */ getchO ; elosegraph ();

return 0;

}