资源描述:
《C语言图形库函数》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.初始化图形系统 函数名:initgraph功 能:初始化图形系统用 法:voidfarinitgraph(intfar*graphdriver,intfar*graphmode, charfar*pathtodriver);程序例:#include#include#include#includeintmain(void){ /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; /*initializegraphicsmode*/
2、 initgraph(&gdriver,&gmode,""); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode!=grOk) /*anerroroccurred*/ { printf("Graphicserror:%s",grapherrormsg(errorcode)); printf("Pressanykeytohalt:"); getch(); exit(1); /*returnwitherrorcode*/ } /*dra
3、waline*/ line(0,0,getmaxx(),getmaxy()); /*cleanup*/ getch(); closegraph(); return0;} 2. 函数名:drawpoly功 能:画多边形用 法:voidfardrawpoly(intnumpoints,intfar*polypoints);程序例:#include#include#include#includeintmain(void){ /*requestautodetection*/ intgdriver=DE
4、TECT,gmode,errorcode; intmaxx,maxy; /*ourpolygonarray*/ intpoly[10]; /*initializegraphicsandlocal variables*/ initgraph(&gdriver,&gmode,""); /*readresultofinitialization*/ errorcode=graphresult(); if(errorcode!=grOk) /*anerroroccurred*/ { printf("Graphicserror:%s", graphe
5、rrormsg(errorcode)); printf("Pressanykeytohalt:"); getch(); /*terminatewithanerrorcode*/ exit(1); } maxx=getmaxx(); maxy=getmaxy(); poly[0]=20; /*1stvertext*/ poly[1]=maxy/2; poly[2]=maxx-20;/*2nd*/ poly[3]=20; poly[4]=maxx-50;/*3rd*/ poly[5]=maxy-20; poly[6]=maxx/2;
6、/*4th*/ poly[7]=maxy/2;/* drawpolydoesn'tautomaticallyclose thepolygon,sowecloseit.*/ poly[8]=poly[0]; poly[9]=poly[1]; /*drawthepolygon*/ drawpoly(5,poly); /*cleanup*/ getch(); closegraph(); return0;} 函数名:ellipse功 能:画一椭圆用 法:voidfarellipse(intx,inty,intstangle,intendangle, intxrad
7、ius,intyradius);程序例:#include#include#include#includeintmain(void){ /*requestautodetection*/ intgdriver=DETECT,gmode,errorcode; intmidx,midy; intstangle=0,endangle=360; intxr