void draw_circle( uint8_t img[],
unsigned int cols,
unsigned int rows,
int x,
int y,
int r,
uint8_t color )
{
int leftT, rightT, leftB, rightB;
//vertical = radius
if(x<cols && x>=0){
for(int i=y-r; i<=y+r; i++){
if(i>=0 && i<rows){
img[x+i*cols]=color;
}
}
}
//horizontal = radius
if(y>=0 && y<rows){
for(int i=x-r; i<=x+r; i++){
if(i>=0 && i<cols){
img[i+y*cols]=color;
}
}
}
// y= y1 + (sqrt)(r^2-x^2)
for(int xx =1; xx<r; xx++){
int yy= (int)sqrt(r**2 - xx**2)+y;
// top left to top right - indexes
leftT = x-xx+(y-yy)*cols;
rightT = x+xx+(y-yy)*cols;
//for loop to draw one line across
for(int i=leftT; i<=rightT; i++){
if(i>=0 && i<cols*rows){
img[i]=color;
}
}
//bottom left to bottom right
leftB = x-xx+(y+yy)*cols;
rightB = x+xx+(y+yy)*cols;
for(int i=leftB; i<=rightB; i++){
if(i>=0 && i<cols*rows){
img[i]=color;
}
}
}
}
No comments:
Post a Comment