From 606c5681b7915eb929af5bdc99adf5d802c5583c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 25 Apr 2021 22:31:09 -0700 Subject: bresenham circles Known issue: circles of radius 9 crash. (Multiples of 9 overflow the trace.) --- shell/data.limg | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'shell') 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)) ) -- cgit 1.4.1-2-gfad0