分类: LINUX
2008-05-26 15:33:40
在LCD驱动中添加了画圆的函数,采用中点法进行迭代:我同学的程序,真有思想!
有圆的对称,判别式等,只是用到的点从(0,R)到(x=y)的坐标。参考有:
中点法,很好。
/*********************************************************************************************
* name: lcd_draw_circle()
* func: Draw circle with appointed color
* para:
* ucColor -- appointed color value
* ret: none
* modify:
* comment:
*********************************************************************************************/
void lcd_draw_circle(UINT16T usX, UINT16T usY, UINT16T usR, UINT8T usColor)
{
/* using midpoint method to draw the circle */
INT16T x, y;
INT16T f;
x = 0;
y = usR;
f = 1 - usR;
LCD_PutPixel(usX+x, usY+y, usColor);
while(x<=y)
{
if(f<0)
f += x*2 + 3;
else
{
f += (x-y)*2 + 5;
--y;
}
++x;
LCD_PutPixel(usX+x, usY+y, usColor); /* 2th division */
LCD_PutPixel(usX-x, usY+y, usColor); /* 3th division */
LCD_PutPixel(usX+y, usY+x, usColor); /* 1th division */
LCD_PutPixel(usX-y, usY+x, usColor); /* 4th division */
LCD_PutPixel(usX-x, usY-y, usColor); /* 6th division */
LCD_PutPixel(usX+x, usY-y, usColor); /* 7th division */
LCD_PutPixel(usX-y, usY-x, usColor); /* 5th division */
LCD_PutPixel(usX+y, usY-x, usColor); /* 8th division */
}
}