|
Turbo C 2.0、Borland C++库函数及用例(36) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); /* terminate with an error code */ exit(1); } midx = getmaxx() / 2; midy = getmaxy() / 2;/* draw arc and get coordinates */ setcolor(getmaxcolor()); arc(midx, midy, stangle, endangle, 100); getarccoords(&arcinfo);/* convert arc information into strings */ sprintf(sstr, "*- (%d, %d)", arcinfo.xstart, arcinfo.ystart); sprintf(estr, "*- (%d, %d)", arcinfo.xend, arcinfo.yend); /* output the arc information */ outtextxy(arcinfo.xstart, arcinfo.ystart, sstr); outtextxy(arcinfo.xend, arcinfo.yend, estr); /* clean up */ getch(); closegraph(); return 0; } 函数名: getASPectratio 功 能: 返回当前图形模式的纵横比 用 法: void far getaspectratio( int far *xasp, int far *yasp ); 程序例:#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h>int main(void) {/* request auto detection */ int gdriver = DETECT, gmode, errorcode; int xasp, yasp, midx, midy;/* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "");/* read result of initialization */ errorcode = graphresult();/* an error occurred */ if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); /* terminate with an error code */ exit(1); } midx = getmaxx() / 2; midy = getmaxy() / 2; setcolor(getmaxcolor());/* get current aspect ratio settings */ getaspectratio(&xasp, &yasp);/* draw normal circle */ circle(midx, midy, 100); getch();/* draw wide circle */ cleardevice(); setaspectratio(xasp/2, yasp); circle(midx, midy, 100); getch();/* draw narrow circle */ cleardevice(); setaspectratio(xasp, yasp/2); circle(midx, midy, 100);/* clean up */
|