commit e7cb2b545007046702cb3316a05a070d30a10c13
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 9 07:57:44 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 9 07:57:44 2020 -0600
implement circfill
---
source/fakecart.c | 2 ++
source/graphics.c | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/source/fakecart.c b/source/fakecart.c
index bb6edf1..6ab5448 100644
--- a/source/fakecart.c
+++ b/source/fakecart.c
@@ -46,6 +46,8 @@ void _draw() {
line(0, 30, 20, 20, 12);
circ(90, 90, 30, 8);
+
+ circfill(100, 100, 15, 9);
}
void _update() {
diff --git a/source/graphics.c b/source/graphics.c
index 9dc9269..9b369d4 100644
--- a/source/graphics.c
+++ b/source/graphics.c
@@ -160,6 +160,26 @@ void circ(short ox, short oy, short r, uint16_t col){
}
void circfill(short ox, short oy, short r, uint16_t col){
+ if (r == 0) {
+ pset(ox, oy, col);
+ }
+ else if (r == 1) {
+ pset(ox, oy - 1, col);
+ line(ox-1, oy, ox+1, oy, col);
+ pset(ox, oy + 1, col);
+ }
+ else if (r > 0) {
+ short x = -r, y = 0, err = 2 - 2 * r;
+ do {
+ line(ox - x, oy + y, ox + x, oy + y, col);
+ line(ox - x, oy - y, ox + x, oy - y, col);
+ r = err;
+ if (r > x)
+ err += ++x * 2 + 1;
+ if (r <= y)
+ err += ++y * 2 + 1;
+ } while (x < 0);
+ }
}