void midpoint_ellipse(int xaxis,int yaxis,int a,int b)
{
int x=0,y=b;
int aa=a*a,bb=b*b;
int aa2=2*a*a,bb2=2*b*b;
float p=b*b-a*a*b+0.25*a*a;
draw_ellipse(xaxis,yaxis,x,y);
while(bb2*x<=aa2*y)
{
x++;
if(p<=0)
{
p=p+bb2*x+bb;
}
else
{
y--;
p=p+bb2*x+bb-aa2*y;
}
draw_ellipse(xaxis,yaxis,x,y);
x=-x;
draw_ellipse(xaxis,yaxis,x,y);
x=-x;
}//end while
x=a;
y=0;
draw_ellipse(xaxis,yaxis,x,y);
p=aa+bb2*a+bb*0.25;
//p=bb*(x+0.5)*(x+0.5)+aa*(y-1)*(y-1)-aa*bb;
while(bb2*x>aa2*y) {
y++;
//fy=fy-aa2;
if(p>0)
{
p=p+aa-aa2*y;
}
else
{
x--;
p=p+bb2*x-aa2*y+aa;
}
draw_ellipse(xaxis,yaxis,x,y);
y=-y;
draw_ellipse(xaxis,yaxis,x,y);
y=-y;
}
}
void draw_ellipse(int xaxis,int yaxis,int x,int y)
{
putpixel(xaxis+x,yaxis+y,4);
putpixel(xaxis-x,yaxis+y,4);
putpixel(xaxis+x,yaxis-y,4);
putpixel(xaxis-x,yaxis-y,4);
}
No comments:
Post a Comment