算法一
void gl_drawCir(int32 x,int32 y,int32 r,uint32 color){
int ix,iy;
for(ix=x-r;ix<x+r;ix++){
for(iy=y-r;iy<y+r;iy++){
if(gl_getLineSize(ix,iy, x,y)<= r*r){
//考虑效率问题,不透明的圆单独处理
if(color>>24==0xff){
mrc_drawPoint(ix,iy, MAKECOLOR565(color));
}
else{
gl_drawPoint(ix,iy, color);
}
}
}
}
//printf("color>>24 = %d\n",color>>24);
}
算法二
void gl_drawCir(int x0,int y0,int r, uint32 color)
{
//使用正负法画圆
int x, y, f;//(x,y)为当前坐标 f为误差值
x = x0;
y = y0 + r;
f = 0;
while(y >= y0){//从圆周的右上部分开始
gl_drawLine( x, y, 2 * x0 - x, y,color);
gl_drawLine( x, 2 * y0 -y, 2 * x0 - x, 2 * y0 -y,color);
if(f > 0){
f = f - 2 * (y - y0) + 1;
y--;//向圆内走
}
else{
f = f + 2 * (x - x0) + 1;
x++;//向圆外走
}
}
if(y == y0)
gl_drawPoint( x, y,color);
}
算法三
void drawCircle(int x, int y, int radius, unsigned int color)
{
int i = 0;
int tx = 0, ty = radius, d = 3 - (radius << 1);
while (tx < ty)
{
for (i = x - ty; i <= x + ty; ++i)
{
gl_drawPoint( i, y - tx, color);
if (tx){
gl_drawPoint( i, y + tx, color);
}
}
if (d < 0)
d += (tx << 2) + 6;
else
{
for (i = x - tx; i <= x + tx; ++i)
{
gl_drawPoint( i, y - ty, color);
gl_drawPoint( i, y + ty, color);
}
d += ((tx - ty) << 2) + 10, ty--;
}
tx++;
}
if (tx == ty)
for (i = x - ty; i <= x + ty; ++i)
{
gl_drawPoint( i, y - tx, color);
gl_drawPoint( i, y + tx, color);
}
}
画空心圆
void gl_Circle(int x0,int y0,int r, uint32 color)
{
//使用正负法画圆
int x, y, f;//(x,y)为当前坐标 f为误差值
x = x0;
y = y0 + r;
f = 0;
while(y >= y0){//从圆周的右上部分开始
gl_drawPoint( x, y,color);//对称地画出四个象限内的坐标点
gl_drawPoint( 2 * x0 - x, y,color);
gl_drawPoint( x, 2 * y0 -y,color);
gl_drawPoint( 2 * x0 - x, 2 * y0 -y,color);
if(f > 0){
f = f - 2 * (y - y0) + 1;
y--;//向圆内走
}
else{
f = f + 2 * (x - x0) + 1;
x++;//向圆外走
}
}
if(y == y0)
gl_drawPoint( x, y,color);
}