#include
#include /*预定义库函数*/
void circlePoint(int x,int y) /*八分法画圆程序*/
{
circle(320+x*20,240+y*20,3);
circle(320+y*20,240+x*20,3);
circle(320-y*20,240+x*20,3);
circle(320-x*20,240+y*20,3);
circle(320-x*20,240+y*20,3);
circle(320-x*20,240-y*20,3);
circle(320-y*20,240-x*20,3);
circle(320+y*20,240-x*20,3);
circle(320+x*20,240-y*20,3);
}
void MidBresenhamcircle(int r) /* 中点Bresenham算法画圆的程序 */
{
int x,y,d;
x=0;y=r;d=1-r; /* 计算初始值 */
while(x { circlePoint(x,y); /* 绘制点(x,y)及其在八分圆中的另外7个对称点 */
if(d<0) d+=2*x+3; /* 根据误差项d的判断,决定非最大位移方向上是走还是不走 */
else
{ d+=2*(x-y)+5;
y--;
}
x++;
delay(900000);
} /* while */
}
main()
{
int i,j,r,graphmode,graphdriver;
detectgraph(&graphdriver,&graphmode);
initgraph(&graphdriver,&graphmode," ");
printf("中点Bresenhamcircle算法画圆的程序n"); /*提示信息*/
printf("注意 |r|<=11");
printf("n输入半径值 r:");
scanf("%d",&r);
printf("按任意键显示图形...");
getch();
cleardevice();
setbkcolor(BLACK);
for(i=20;i<=620;i+=20) /*使用双循环画点函数画出表格中的纵坐标*/
for(j=20;j<=460;j++)
putpixel(i,j,2);
for(j=20;j<=460;j+=20)