void lcd_circle(int8 x_ctr,int8 y_ctr,int8 radius,int8 pen_size,int8 solid,int8 set_clr)
{
int8 x,y,r,x1,y1;
signed int16 delta;
// The axis is shrunk to reflect the aspect ratio
// this uses bresenham's algorithm
// theory
// 0=x^2+y^2-r^2 is true circle centered at 0,0
// error is x^2+y^2-r^2
// looking at north to north east octant
// pixels are * 0
// 0
// algorithm chooses pixel due east or south east
// * has the coord (x,y) both 0 pixels have an x coord of x+1
// mid pt has coord of (x+1,y+1/2)
// error is (x+1)^2+(y+1/2)^2 -r^2
// error >0 draw south east ( x+1,y-1) pixel else draw east pixel (x+1,y)
// now we can compute the error in advance for the next iteration
// change in error from (x+1,y-1/2) to (x+2,y-1/2) is 2x+3
// (x+1,y-1/2) to (x+2,y-3/2) 2x+3 -2y+2
// Note: delta is the error in the code below
// if delta is <0 then we decrement y
r=48;
if (radius<48) r=radius; // max radius is 48 pixels
if (solid) pen_size=1;
for (r=radius-pen_size;r<=radius;r++)
{
x=0;
y=r;
// assume last step was to south east pixel from (0,r) or 2*0-2*r+5
delta=(long)5-(long)2*(long)r;
loop:
y1=(long)y*(long)5/(long)6; /// aspect ratio
x1=(long)x*(long)5/(long)6; /// aspect ratio
if(solid)
{
lcd_line(x_ctr+x, y_ctr-y1, x_ctr+x, y_ctr+y1, set_clr);
lcd_line(x_ctr-x, y_ctr-y1, x_ctr-x, y_ctr+y1, set_clr);
lcd_line(x_ctr+y, y_ctr-x1, x_ctr+y, y_ctr+x1, set_clr);
lcd_line(x_ctr-y, y_ctr-x1, x_ctr-y, y_ctr+x1, set_clr);
}
else
{
lcd_setpixel(x_ctr+x,y_ctr+y1,set_clr);
lcd_setpixel(x_ctr+x,y_ctr-y1,set_clr);
lcd_setpixel(x_ctr-x,y_ctr+y1,set_clr);
lcd_setpixel(x_ctr-x,y_ctr-y1,set_clr);
lcd_setpixel(x_ctr+y,y_ctr+x1,set_clr);
lcd_setpixel(x_ctr+y,y_ctr-x1,set_clr);
lcd_setpixel(x_ctr-y,y_ctr+x1,set_clr);
lcd_setpixel(x_ctr-y,y_ctr-x1,set_clr);
}
}
if (delta<0) delta=delta+(long)2*(long)x+(long)3;
else {delta=delta+(long)2*((long)x-(long)y)+(long)5;y=y-1;}
x=x+1;
if (x<=y) goto loop;
}