在tc下,用中点画圆法如何画出一个圆,我做了老半天,只能画出1/8圆,希望大家能帮我解答啊,谢谢,程序如下:
#include<stdio.h>
#include<graphics.h>
void MidPointCircle(int r,int color);
void CirclePoints(int x,int y,int color);
main()
{
int gdriver=DETECT, gmode;
initgraph(&gdriver, &gmode," ");
setbkcolor(WHITE);
MidPointCircle(1,BLUE);
getch();
closegraph();
}
void MidPointCircle(int r,int color)
{
int x,y;
float d;
x=0;y=r;d=1.25-r;
CirclePoints(x,y,color);
while(x<=y)
{
if(d<0)
d+=2*x+3;
else
{d+=2*(x-y)+5;y--;}
x++;
putpixel(x,y,color);
}
}
void CirclePoints(int x,int y,int color)
{
putpixel(x,y,color);putpixel(y,x,color);
putpixel(-x,y,color);putpixel(y,-x,color);
putpixel(x,-y,color);putpixel(-y,x,color);
putpixel(-x,-y,color);putpixel(-y,-x,color);
}