Created
June 22, 2012 16:48
-
-
Save martintrojer/2973933 to your computer and use it in GitHub Desktop.
Bresenham
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn draw-line! | |
"Draws a line (bresenham algorithm)" | |
[color [c0 r0] [c1 r1] screen] | |
(let [dc (- c1 c0) | |
dr (- r1 r0) | |
derr (Math/abs (/ dr dc))] | |
(loop [err derr | |
r r0 | |
c c0] | |
(when (< c c1) | |
(set-pixel! color c r screen) | |
(if (> err 0.5) | |
(recur (dec (+ err derr)) (inc r) (inc c)) | |
(recur (+ err derr) r (inc c))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment