# One more circle algorith

Of the ones I have tried this (BresnHam Method) still seems the best. I can get slightly better circles using sin/cosine tables but it takes 4 times as many steps to
get only a slightly better result. To test I drew 600 concentric circles with radii from 1 to 600 (1200 screen height) then a screen update and look for holes. Too many holes and you will get bizzare artifacts (gaps appear ) when you zoom in/out This one gets a few when I zoom out the BMP screen caps with PSP, but that is not
a real problem.

void (jbSDL_DrawPixel) (SDL_Surface * dst, Uint16 x, Uint16 y, Uint32 pixel); / This is from the libsdl.org draw pixel example. Not included */

# /*=======================================================================================================================

*/

int jbSDL_DrawCircle(SDL_Surface *uscreen, const short xc, const short yc, const unsigned short radius, const unsigned short dsp_width,
const unsigned short dsp_height, Uint32 ucolor)

{
short x,x2,y2;
short w,r,d;

x = 0;
d = 2 * (1 - radius);

w = 2.0 * dsp_width / dsp_height;

while(r >= 0)
{

x2 = xc + x;
y2 = yc + r;
if(x2 >= 0 && x2 <= dsp_width && y2 >= 0 && y2 <= dsp_height) (*jbSDL_DrawPixel) (uscreen, x2, y2, ucolor);

y2 = yc - r;
if(x2 >= 0 && x2 <= dsp_width && y2 >= 0 && y2 <= dsp_height) (*jbSDL_DrawPixel) (uscreen, x2, y2, ucolor);

x2 = xc - x;
y2 = yc + r;
if(x2 >= 0 && x2 <= dsp_width && y2 >= 0 && y2 <= dsp_height) (*jbSDL_DrawPixel) (uscreen, x2, y2, ucolor);

y2 = yc - r;
if(x2 >= 0 && x2 <= dsp_width && y2 >= 0 && y2 <= dsp_height) (*jbSDL_DrawPixel) (uscreen, x2, y2, ucolor);

if (d + r > 0)
d -= (w * --r) - 1;
if (x > d)
d += (2 * ++x) + 1;
}

return 0;
}

Interesting. You could also try modifying the putpixel function to do xor instead, then draw circles with one algorithm, and draw the same circles again with the other algorithm. What’s left are your artifacts. Probably a better test than your for finding all the artifacts.

Might want to be sure you don’t have any rounding error problems resulting from your sin/cosine table method. Remember, just using int(x) will round x down and never up. That would cause artifacts in your basis algorithm that you thought was perfect.

-Jason----- Original Message -----
From: J BB
To: sdl at libsdl.org
Sent: Friday, March 15, 2002 3:52 AM
Subject: [SDL] One more circle algorith

Of the ones I have tried this (BresnHam Method) still seems the best. I can get slightly better circles using sin/cosine tables but it takes 4 times as many steps to
get only a slightly better result. To test I drew 600 concentric circles with radii from 1 to 600 (1200 screen height) then a screen update and look for holes. Too many holes and you will get bizzare artifacts (gaps appear ) when you zoom in/out This one gets a few when I zoom out the BMP screen caps with PSP, but that is not
a real problem.