Hi guys,
At request I decided to write a thread with some basic library functions for any graphic LCD screen.
DRAW CIRCLE
First up will be a basic routine to draw a circle. Full and total credit for this routine goes to Pommie. I pinched it out of a thread here somewhere.
- Requirements: A PutPixel Function. The PutPixel function must check and ignore if the pixel is off-screen.
If you only have a mono LCD, then remove all references to 'color' out of the prototype and out of the function.
At request I decided to write a thread with some basic library functions for any graphic LCD screen.
DRAW CIRCLE
First up will be a basic routine to draw a circle. Full and total credit for this routine goes to Pommie. I pinched it out of a thread here somewhere.
- Requirements: A PutPixel Function. The PutPixel function must check and ignore if the pixel is off-screen.
Code:
//Function Prototype
void DrawCircle(unsigned int xpos, unsigned char ypos, unsigned int R, unsigned int color);
// Routine
void DrawCircle(unsigned int xpos, unsigned char ypos, unsigned int R, unsigned int color){
unsigned int y,x;
signed int p;
x=0;
y=R;
p= -(R/2);
Plot8(xpos,ypos,x,y, color);
while(x<y){
x++;
if(p<0)
p=p+2*x+1;
else{
y--;
p=p+2*(x-y)+1;
}
Plot8(xpos, ypos, x, y, color);
}
}
void Plot8(unsigned char x,unsigned char y,unsigned char dx,unsigned char dy, unsigned int color){
PutPixel(x + dx, y + dy, color);
PutPixel(x + dx, y - dy, color);
PutPixel(x - dx, y + dy, color);
PutPixel(x - dx, y - dy, color);
PutPixel(x + dy, y + dx, color);
PutPixel(x + dy, y - dx, color);
PutPixel(x - dy, y + dx, color);
PutPixel(x - dy, y - dx, color);
}
// example
DrawCircle(63, 32, 20, Red);
If you only have a mono LCD, then remove all references to 'color' out of the prototype and out of the function.
Last edited: