diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-05-07 11:28:59 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-05-07 11:28:59 -0700 |
commit | 91f76e6b228dbe6ff74b7b657fd9dc79d10f8909 (patch) | |
tree | 1a479c1f6664b57618178f9de29d3aac185445f2 /shell/data.limg | |
parent | 25eb9c580e63a84555873b9f67a261004d9f38c3 (diff) | |
download | mu-91f76e6b228dbe6ff74b7b657fd9dc79d10f8909.tar.gz |
clean up Bresenham line-drawing
Diffstat (limited to 'shell/data.limg')
-rw-r--r-- | shell/data.limg | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/shell/data.limg b/shell/data.limg index dd40fbdc..f276e9b5 100644 --- a/shell/data.limg +++ b/shell/data.limg @@ -23,32 +23,28 @@ (hline1 screen y1 x1 x2 color) (set y1 (+ y1 1)))))]) (brline . [(def brline (fn (screen x0 y0 x1 y1 color) - ((fn (dx dy sx sy) - ((fn (err) - (brline1 screen x0 y0 x1 y1 dx dy sx sy err color)) - (+ dx dy))) - (abs (- x1 x0)) - (- 0 (abs (- y1 y0))) - (sgn (- x1 x0)) - (sgn (- y1 y0)))))]) - (brline1 . [(def brline1 (fn (screen x y xlast ylast dx dy sx sy err color) - (while (not (and (= x xlast) (= y ylast))) + (let (x y) `(,x0 ,y0) + (let dx (abs (- x1 x0)) + (let dy (- 0 (abs (- y1 y0))) + (let sx (sgn (- x1 x0)) + (let sy (sgn (- y1 y0)) + (let err (+ dx dy) + (while (not (and (= x x1) + (= y y1))) (pixel screen x y color) - ((fn (e2) - (if (>= e2 dy) - (set x (+ x sx)) - ()) - (if (<= e2 dx) - (set y (+ y sy))) - (set err (+ err - (+ - (if (>= e2 dy) - dy - 0) - (if (<= e2 dx) - dx - 0))))) - (* err 2)))))]) + (let e2 (* err 2) + (when (>= e2 dy) + (set x (+ x sx))) + (when (<= e2 dx) + (set y (+ y sy))) + (set err + (+ err + (+ (if (>= e2 dy) + dy + 0) + (if (<= e2 dx) + dx + 0))))))))))))))]) (read_line_2 . [(def read_line_2 (fn (keyboard stream) ((fn (c) (if (= c 10) @@ -97,5 +93,5 @@ (main . [(def main (fn (screen keyboard) (chessboard screen 16)))]) )) - (sandbox . (fill_rect screen 0 0 8 8 2)) + (sandbox . (brline screen 1 1 5 5 4)) ) |