Hi there, staff and enthusiasts.

I see you’ve added a line drawing function, dissimilar with the one I made for my own program, but that’s mostly optimization.

So I decided maybe my Circle Drawing function might go through some optimization and join the process.

It basically follows the (x-x1)*(x-x1)+(y-y1)*(y-y1)=r*r geometry formula by x and y, drawing between the 45 degree diagonals (hence the division by square root of 2). I have some ideas about modifying it to work for making an ellipse, and a simple tweak that could determine fill (0 = no fill, otherwise give fill color). I realize the three color parameters can be put into one, and there are other tweaks to be done for supporting multiple bpp formats, but I want your opinions on this. It’s “void” because I didn’t really need program level confirmation, but visual.

Code:

void SDL_DrawCircle(SDL_Surface *screen, const Uint16 x, const Uint16 y, const Uint8 r, const Uint8 bpp, const Uint8 R, const Uint8 G, const Uint8 B)

{

Uint32 color1 = SDL_MapRGB(screen->format, R, G, B);

Uint32 *bufp1,*bufp2;
Uint16 rsqr = r*r,tx,tx1,tx2,ty,ty1,ty2;

float tmpy,tmpx;

```
tmpx= -ceil(r/sqrt((float)2));
while(tmpx <= (float) r)
{
if( (float)fabs(tmpx) < (float)r/sqrt((float)2)){
tmpy = sqrt((float)(rsqr - pow(tmpx,2)));
ty1=y+ (Uint16) floor(tmpy+0.5);
ty2=y- (Uint16) floor(tmpy+0.5);
tx=x-(Uint16) tmpx;
bufp1 = (Uint32 *)screen->pixels + ty1*screen->pitch/bpp + tx;
bufp2 = (Uint32 *)screen->pixels + ty2*screen->pitch/bpp + tx;
*bufp1 = color1;
*bufp2 = color1;
}
tmpx++;
}
tmpy = -ceil(r/sqrt((float)2));
while(tmpy <= (float) r)
{
if( (float)fabs(tmpy) < (float)r/sqrt((float)2)){
tmpx = sqrt((float)(rsqr - pow(tmpy,2)));
tx1=x+ (Uint16) floor(tmpx+0.5);
tx2=x- (Uint16) floor(tmpx+0.5);
ty=y-(Uint16) tmpy;
bufp1 = (Uint32 *)screen->pixels + ty*screen->pitch/bpp + tx1;
bufp2 = (Uint32 *)screen->pixels + ty*screen->pitch/bpp + tx2;
*bufp1 = color1;
*bufp2 = color1;
}
tmpy++;
}
```

}