+/EE445L
embedded systems
git clone https://git.julia.blue/+/EE445L
5c1089c
master
1#include "graphics.h" 2#include "ST7735.h" 3#include <stdlib.h> 4 5void draw_line (int32_t x0 ,int32_t y0 ,int32_t x1 ,int32_t y1 ,uint32_t color ) { 6int dx = abs (x1 - x0 ),sx = x0 < x1 ?1 :-1 ; 7int dy = abs (y1 - y0 ),sy = y0 < y1 ?1 :-1 ; 8int err = (dx > dy ?dx :- dy ) /2 ,e2 ; 9ST7735_DrawPixel (x0 ,y0 ,color ); 10while (!(x0 == x1 && y0 == y1 )) { 11ST7735_DrawPixel (x0 ,y0 ,color ); 12e2 = err ; 13if (e2 > - dx ) { 14err -= dy ; 15x0 += sx ; 16 } 17if (e2 < dy ) { 18err += dx ; 19y0 += sy ; 20 } 21ST7735_DrawPixel (x0 ,y0 ,color ); 22 } 23} 24 25void circle_helper (uint32_t xc ,uint32_t yc ,uint32_t x ,uint32_t y , 26uint32_t color ) { 27ST7735_DrawPixel (xc + x ,yc + y ,color ); 28ST7735_DrawPixel (xc - x ,yc + y ,color ); 29ST7735_DrawPixel (xc + x ,yc - y ,color ); 30ST7735_DrawPixel (xc - x ,yc - y ,color ); 31ST7735_DrawPixel (xc + y ,yc + x ,color ); 32ST7735_DrawPixel (xc - y ,yc + x ,color ); 33ST7735_DrawPixel (xc + y ,yc - x ,color ); 34ST7735_DrawPixel (xc - y ,yc - x ,color ); 35} 36 37void draw_circle (uint32_t xc ,uint32_t yc ,uint32_t r ,uint32_t color ) { 38int x = 0 ,y = r ; 39int d = 3 - 2 * r ; 40circle_helper (xc ,yc ,x ,y ,color ); 41while (y >=x ) { 42x ++ ; 43if (d > 0 ) { 44y -- ; 45d = d + 4 * (x - y )+ 10 ; 46 }else 47d = d + 4 * x + 6 ; 48circle_helper (xc ,yc ,x ,y ,color ); 49 } 50}