LCD通过绘点的方式画一个圆

 1 /***********************************************************************************************************************   
 2 **    function name:   void lcd_draw_point(uint16_t x0,uint16_t y0,uint16_t color)
 3 **    description:     以特定颜色绘制一个点
 4 **    input para:         x0,y0表示坐标,color表示颜色
 5 **                      
 6 **    return:                无                            
 7 ***********************************************************************************************************************/
 8 void lcd_draw_point(uint16_t x0,uint16_t y0,uint16_t color)
 9 {
10     //绘点函数,不同IC不同,根据驱动定义
11     //.............
12     //.............
13 }
14 
15 /***********************************************************************************************************************   
16 **    function name:   void draw_circle(uint16_t x0,uint16_t y0,uint8_t r,uint16_t color) 
17 **    description:     以特定颜色绘一个圆
18 **    input para:         x0,y0表示中心坐标,r表示半径,color圆的颜色
19 **                      
20 **    return:                无                            
21 ***********************************************************************************************************************/
22 void draw_circle(uint16_t x0,uint16_t y0,uint8_t r,uint16_t color) //圆心(x0,y0),半径r
23 {
24     uint16_t i,y;
25     if((x0 < r) || (y0 < r))            //保证能画出完整的圆
26         return;
27        
28     for(i = x0-r; i <= x0; i++){
29         y = sqrt(pow(r,2)-pow((x0-i),2)); //求出在垂直坐标上的偏移
30         //画左上半圆
31         lcd_draw_point(i,y0-y,color);
32         //画左下半圆
33         lcd_draw_point(i,y0+y,color);
34         //画右上半圆
35         lcd_draw_point(x0*2-i,y0-y,color);
36         //画右下半圆
37         lcd_draw_point(x0*2-i,y0+y,color);
38     }
39 }

代码直接如上,大概思路就是以横向直径为参考,每个像素绘一个点。因为计算会存在小数,所以半径越小效果越差。

原文地址:https://www.cnblogs.com/zwj412/p/11836621.html