这是我以前做的一个程序, 你参考下。
//brush -是否填充
//color - 边沿颜色
//bcolor- 填充颜色
void ellipsepoint(int x,int y,int x0,int y0, Color color , Color bcolor, bool brush) //
{
MLine ln;
//LCD_DrawPoint
LCD_SetPixel( x+x0, y+y0, color);
LCD_SetPixel(-x+x0, y+y0, color);
LCD_SetPixel(-x+x0,-y+y0, color);
LCD_SetPixel( x+x0,-y+y0, color);
if(brush)
{
ln.start.x = x+x0-1 , ln.start.y = y+y0-1, ln.end.x = -x+x0+1, ln.end.y = y+y0-1, ln.color = bcolor, LCD_DrawLine(ln);
ln.start.x = x+x0-1 , ln.start.y =-y+y0+1, ln.end.x = -x+x0+1, ln.end.y =-y+y0+1, ln.color = bcolor, LCD_DrawLine(ln);
}
}
void LCD_DrawEllipse(pMEllipse e, bool brush) //椭圆画法
{
int a = e->a, b = e->b;
Color color= e->pencolor;
int x = 0, y = b ;
float d1,d2;
d1=b*b+a*a*(-b+0.25);
while (b*b*(x+1)<a*a*(y-0.5))
{
ellipsepoint(x,y,e->p.x,e->p.y,color, e->brushcolor, brush);
if(d1<=0)
{
d1+=b*b*(2*x+3);
x++;
}
else
{
d1+=b*b*(2*x+3)+a*a*(-2*y+2);
x++;
y--;
}
}
ellipsepoint(x,y,e->p.x,e->p.y,color, e->brushcolor, brush);
d2=b*b*(x+0.5)*(x+0.5)+a*a*(y-1)*(y-1)-a*a*b*b;
while(y>=0)
{
if(d2<=0)
{
d2+=b*b*(2*x+2)+a*a*(-2*y+3);
x++;
y--;
}
else
{
d2+=a*a*(-2*y+3);
y--;
}
ellipsepoint(x,y,e->p.x,e->p.y,color, e->brushcolor, brush);
}
} |