1、graphicsh 功能graphics.h 功能函数名称: getarccoords函数原型: void far getarccoords(struct arccoordstype far *coords)函数功能: 得到最后一次画圆弧的坐标函数返回:参数说明: coords-使用函数arc()画圆弧的坐标,该结构如下: struct arccoordstype int m,n;/* 圆心坐标 */ int xstart,ysrart,xend,yend;/* 圆弧起点终点坐标 */ ;所属文件: <graphics.h>#include <graphics.h>#i
2、nclude <stdlib.h>#include <stdio.h>#include <conio.h>int main() int gdriver=DETECT,gmode,errorcode; struct arccoordstype arcinfo; int midx,midy; int stangle=45,endangle=270; char sstr80,estr80; initgraph(&gdriver,&gmode,); errorcode=graphresult(); if (errorcode!=grOk) printf(Graphi
3、cs error: %s,grapherrormsg(errorcode); printf(ress any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(getmaxcolor(); arc(midx,midy,stangle,endangle,100); getarccoords(&arcinfo); sprintf(sstr,*- (%d,%d),arcinfo.xstart,arcinfo.ystart); sprintf(estr,*- (%d,%d),arcinfo.xen
4、d,arcinfo.yend); outtextxy(arcinfo.xstart,arcinfo.ystart,sstr); outtextxy(arcinfo.xend,arcinfo.yend,estr); getch(); closegraph(); return 0;函数名称: arc函数原型: void far arc(int x, int y, int start, int end, int radius)函数功能: 画一圆弧线函数返回:参数说明: x,y-圆心,radius-半径,start,end-弧线的起始和中止角度所属文件: <graphics.h>#incl
5、ude <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main() int gdriver=DETECT,gmode,errorcode; int midx,midy; int stangle=45,endangle=135; int radius=100; initgraph(&gdriver,&gmode,); errorcode=graphresult(); if (errorcode!=grOk) printf(Graphics error:
6、%s,grapherrormsg(errorcode); printf(ress any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(getmaxcolor(); arc(midx,midy,stangle,endangle,radius); getch(); closegraph(); return 0;函数名称: circle函数原型: void far circle(int x, int y, int radius)函数功能: 画圆函数返回:参数说明: x,y-圆心坐标,rad
7、ius-半径所属文件: <graphics.h>#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main() int gdriver=DETECT,gmode,errorcode; int midx,midy; int radius=100; initgraph(&gdriver,&gmode,); errorcode=graphresult(); if (errorcode!=grOk) printf(Graphics e
8、rror: %s,grapherrormsg(errorcode); printf(ress any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(getmaxcolor(); circle(midx,midy,radius); getch(); closegraph(); return 0;函数名称: pieslice函数原型: void far pieslice(int x,int y,int start,int end,int radius)函数功能: 画扇形 函数返回:参数说明
9、: x,y-扇形所在园的圆心坐标,start,end-扇形的开始和结束角度,radius-园的半径所属文件: <graphics.h>#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main() int gdriver=DETECT,gmode,errorcode; int midx,midy; int stangle=45,endangle=135,radius=100; initgraph(&gdriver,&gmode
10、,); errorcode=graphresult(); if (errorcode!=grOk) printf(Graphics error: %s,grapherrormsg(errorcode); printf(Press any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; setfillstyle(EMPTY_FILL,getmaxcolor(); pieslice(midx,midy,stangle,endangle,radius); getch(); closegraph(); retur
11、n 0;函数名称: getaspectratio,setaspectratio函数原型: void far getaspectratio(int far *xasp, int far *yasp)函数功能: 得到图形显示的比例因子函数返回:参数说明: xasp-x方向比例因子,yasp-y方向比例因子所属文件: <graphics.h>#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main() int gdriver=DE
12、TECT,gmode,errorcode; int xasp,yasp,midx,midy; initgraph(&gdriver,&gmode,); errorcode=graphresult(); if (errorcode!=grOk) printf(Graphics error: %s,grapherrormsg(errorcode); printf(Press any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(getmaxcolor(); getaspectratio(&
13、xasp,&yasp); circle(midx,midy,100); getch(); cleardevice(); setaspectratio(xasp/2,yasp); circle(midx,midy,100); getch(); cleardevice(); setaspectratio(xasp,yasp/2); circle(midx,midy,100); getch(); closegraph(); return 0;函数名称: sector函数原型: void far sector(int x,int y,int start,int end,int xrad,int yra
14、d)函数功能: 画扇形,并填充以预定填充图案和颜色函数返回:参数说明: x,y-圆心坐标,start,end-圆弧起点和终点角度,单位度,xrad,yrad-椭圆x,y方向的半径所属文件: <graphics.h>#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main(void) /* request auto detection */ int gdriver=DETECT,gmode,errorcode; int mid
15、x,midy,i; int stangle=45,endangle=135; int xrad=100, yrad=50; /* initialize graphics and local variables */ initgraph(&gdriver,&gmode,); /* read result of initialization */ errorcode=graphresult(); if (errorcode!=grOk)/* an error occurred */ printf(Graphics error: %sn,grapherrormsg(errorcode); print
16、f(Press any key to halt:); getch(); exit(1); /* terminate with an error code */ midx=getmaxx()/2; midy=getmaxy()/2; /* loop through the fill patterns */ for(i=EMPTY_FILL;i<USER_FILL;i+) /* set the fill style */ setfillstyle(i,getmaxcolor(); /* draw the sector slice */ sector(midx,midy,stangle,end
17、angle,xrad,yrad); getch(); /* clean up */ closegraph(); return 0;函数名称: ellipse函数原型: void far ellipse(int x,int y,int start,int end,int xradius,int yradius)函数功能: 画椭圆弧函数返回:参数说明: x,y-圆心坐标,start,end-圆弧起点和终点角度,单位为度,xradius,yradius-椭圆x,y方向的半径所属文件: <graphics.h>#include <graphics.h>#include <
18、stdlib.h>#include <stdio.h>#include <conio.h>int main() int gdriver=DETECT,gmode,errorcode; int midx,midy; int stangle=0,endangle=360; int xradius=100,yradius=50; initgraph(&gdriver,&gmode,); errorcode=graphresult(); if (errorcode!=grOk) printf(Graphics error: %s,grapherrormsg(errorco
19、de); printf(Press any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; setcolor(getmaxcolor(); ellipse(midx,midy,stangle,endangle,xradius,yradius); getch(); closegraph(); return 0;函数名称: fillellipse函数原型: void far fillellipse(int x, int y, int xradius, int yradius)函数功能: 画椭圆并用当前的填充色
20、和填充图案填充函数返回:参数说明: x,y-圆心坐标,xradius,yradius-椭圆x,y方向的半径所属文件: <graphics.h>#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main() int gdriver=DETECT,gmode,errorcode; int midx,midy,i; int xradius=100,yradius=50; initgraph(&gdriver,&gmode,); er
21、rorcode=graphresult(); if (errorcode!=grOk) printf(Graphics error: %sn,grapherrormsg(errorcode); printf(Press any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; /* loop through the fill patterns */ for (i=EMPTY_FILL;i<USER_FILL;i+) /* set fill pattern */ setfillstyle(i,getma
22、xcolor(); fillellipse(midx,midy,xradius,yradius); getch(); closegraph(); return 0;函数名称: getfillsettings函数原型: void far getfillsettings(struct fillsettingstype far *info)函数功能: 得到当前填充模式和颜色编号函数返回:参数说明: info-当前填充模式和颜色编号,该结构定义如下: struct fillsettingstype int patterns; int color; 其中patterns定义如下: EMPTY_FILL
23、0背景色填充 SOLID_FILL 1实填充 LINE_FILL 2- 线填充 LTSLASH_FILL 3斜线填充 SLASH_FILL 4粗斜线填充 BKSLASH_FILL 5反粗斜线填充 LTBKSLASH_FILL 6反斜线填充 HATCH_FILL 7网格填充 XHATCH_FILL 8斜网格填充 INTERLEAVE_FILL 9间隔点线填充 WIDE_DOT_FILL10稀疏点填充 CLOSE_DOT_FILL11密集点填充 USER_FILL 12用户自定义填充所属文件: <graphics.h>#include <graphics.h>#includ
24、e <stdlib.h>#include <stdio.h>#include <conio.h>char *fname=EMPTY_FILL,SOLID_FILL,LINE_FILL,LTSLASH_FILL,SLASH_FILL, BKSLASH_FILL,LTBKSLASH_FILL,HATCH_FILL,XHATCH_FILL,INTERLEAVE_FILL, WIDE_DOT_FILL,CLOSE_DOT_FILL,USER_FILL;int main() int gdriver=DETECT,gmode,errorcode; struct fill
25、settingstype fillinfo; int midx,midy; char patstr40,colstr40; initgraph(&gdriver,&gmode,); errorcode=graphresult(); if (errorcode!=grOk) printf(Graphics error: %s,grapherrormsg(errorcode); printf(Press any key to halt:); getch(); exit(1); midx=getmaxx()/2; midy=getmaxy()/2; getfillsettings(&fillinfo
26、); sprintf(patstr,%s is the fill style.,fnamefillinfo.pattern); sprintf(colstr,%d is the fill color.,fillinfo.color); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(midx,midy,patstr); outtextxy(midx,midy+2*textheight(W),colstr); getch(); closegraph(); return 0;函数名称: getfillpattern,setfillpattern函数原型: void far getfillpattern(char far *pattern) void far setfillpattern(char
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1