SayoriOS 0.3.3

circle.c
1 #include "common.h"
2 #include "io/screen.h"
3
4 void draw_circle(int32_t xc, int32_t yc, int32_t radius, uint32_t color) {
5 int32_t x = 0;
6 int32_t y = radius;
7 int32_t delta = 1 - 2 * radius;
8 int32_t error;
9
10 while (y >= 0) {
11 set_pixel(xc + x, yc + y, color);
12 set_pixel(xc + x, yc - y, color);
13 set_pixel(xc - x, yc + y, color);
14 set_pixel(xc - x, yc - y, color);
15
16 error = 2 * (delta + y) - 1;
17
18 if ((delta < 0) && (error <= 0)) {
19 delta += 2 * ++x + 1;
20 continue;
21 }
22
23 if ((delta > 0) && (error > 0)) {
24 delta -= 2 * --y + 1;
25 continue;
26 }
27
28 delta += 2 * (++x - y--);
29 }
30 }
common.h
Основные определения ядра