about summary refs log tree commit diff stats
path: root/shell/data.limg
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-25 22:31:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-25 22:33:26 -0700
commit606c5681b7915eb929af5bdc99adf5d802c5583c (patch)
tree45e23833c52921fc9cf0a99a0d3f51afe113c7e9 /shell/data.limg
parent7148f1222e03303f4f894f4a4c9b3719d17a2f9e (diff)
downloadmu-606c5681b7915eb929af5bdc99adf5d802c5583c.tar.gz
bresenham circles
Known issue: circles of radius 9 crash. (Multiples of 9 overflow the trace.)
Diffstat (limited to 'shell/data.limg')
-rw-r--r--shell/data.limg23
1 files changed, 22 insertions, 1 deletions
diff --git a/shell/data.limg b/shell/data.limg
index c61ebe98..534ecd51 100644
--- a/shell/data.limg
+++ b/shell/data.limg
@@ -67,8 +67,29 @@
                        (fill_rect screen x y (+ x px) (+ y px) color)
                        (set x (+ x px))
                        (set x (+ x px)))))
+    (brcircle . (fn () (screen cx cy r color)
+                  ((fn (x y err continue)
+                     (while continue
+                       (pixel screen (- cx x) (+ cy y) color)
+                       (pixel screen (- cx y) (- cy x) color)
+                       (pixel screen (+ cx x) (- cy y) color)
+                       (pixel screen (+ cx y) (+ cy x) color)
+                       (set r err)
+                       (if (<= r y)
+                         (set err (+ err (+ 1 (* 2 (set y (+ y 1))))))
+                         ())
+                       (if (or (> r x) (> err y))
+                         (set err (+ err (+ 1 (* 2 (set x (+ x 1))))))
+                         ())
+                       (set continue (< x 0))
+                       ))
+                    (- 0 r)
+                    0
+                    (- 2 (* 2 r))
+                    1
+                   )))
     (main . (fn () (screen keyboard)
               (chessboard screen 16)))
   ))
-  (sandbox . (+ 1 2))
+  (sandbox . (brcircle screen 5 5 3 12))
 )