Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Created June 22, 2012 16:48
Show Gist options
  • Save martintrojer/2973933 to your computer and use it in GitHub Desktop.
Save martintrojer/2973933 to your computer and use it in GitHub Desktop.
Bresenham
(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