资源描述:
《图形学报告DDA圆中点多边形填充》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、DDA算法:源代码:#include#include#includevoidinitialize(){intdriver=DETECT,mode;initgraph(&driver,&mode,"..\BGI");}voidLineDDA(intxO,intyOJntxl,intyl,intcolor){intx;floatdy,dxym;dx=x1・xO;dy=yl-yO;m=dy/dx;y二yO;for(x=xO;x<=x1;x++)(putpixel(xXint)
2、(y+0.5),color);y+=m;}}voidmain()主函数{intxO、yO,xl,yl,color;initialize();scanf(”%d,%d,%d,%d,%d”,&xO,&yO,&x1,&y1,&color);LineDDA(xO,yO,x1,y1,color);getch();}结果截图:IBOXDOSBOK®•rZfWHMf■■p0,1Z0j300,400,Z6直线中点算法:源代码:#include#include#includevoidini
3、tialize(){intdriver=DETECT,mode;initgraph(&driver,&mode,"..\BGI");}voidMidPointLine(intxOJntyO,intxl,intyljntcolor){intdx,dy,incrNE,d,x^y;dx=xl-xO;dy=yl-yO;d=dx-2*dy;incrNE=2*(dx-dy);x=xO,y=yO;putpixel(x,y,color);while(x0)d+=incrNE;else{d+=incrNE;y++;x++;}p
4、utpixel(x,y,color);}}voidmain(){intxO,yO,xl,yl,color;scanf("%d,%d,%d,%d,%d”,&xO,&yO,&x1,&y1,&color);MidPointLine(xO,yO,x1,y1,color);getch();}结果截图:中点画圆算法:#include#include#includevoidcircle_pointS(intx.inty,intcolorantxc,intyc){putpixel(x+xc
5、,y+yc,color);putpixel(y+xc,x+yc,color);putpixel(y+xcrx+yc,color);putpixel(x+xc,-y+yc,color);putpixel(-x+xc,-y+yc,color);putpixel(-y+xc,-x+yc,color);putpixel(-y+xc,x+yc,color);putpixel(-x+xc,y+yc,color);}voidBresenham_Circle(intxc,intyc.intrjntcolor){intx,y,d;x=0;y=r;d
6、=3-2*r;while(x=0){d=d+4*(x・y)+10;y二y-1;)elsed=d+4*x+6;x=x+l;}if(x==y)circle_pointS(x,y,color,xc,yc);}voidmain(){intxc,yc,r,color;intgmode=VGAHI,gdriver=VGA;initgraph(&gdriver,&gmode;,C:\TC30\BGF,);printf(nPleaseInput(x,y)andra
7、ndcolorn);scanf("%d,%d,%d,%d",&xc,&yc,&r,&color);Bresenham_Circle(xc,yc,r,color);gelch();结果截图:toxDOSBex0.71^CpuCydewmmqFrane^i^©.PFegrMM>CPleaseInput(x»y)andrandcolor300,260,100>28多边形填充:#include#include#includevoidmain(){intxl,yl,x2,y2,n
8、,i,j;inta[101={100,100,100,400,400,400,400,100,100,100};intgmode=VGAHI,gdriver=VGA;initgraph(&gdriver,&gmode,"C:\TC30\BGI"