Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

bresenham elisp

Name: Anonymous 2014-10-04 19:54

(defun octant0or3 (x0 y0 dx dy xdirection)
"draws a line in octant 0 or 3 (|dx|>=dy).
xdirection: 1 left to right, -1 right to left."
(let* ((dy*2 (* dy 2))
(dy*2-dx*2 (- dy*2 (round (* dx 2))))
(err (- dy*2 (round dx))))
(dot x0 y0)
(while (>= (setq dx (1- dx)) 0)
(if (>= err 0)
(setq y0 (1+ y0)
err (+ err dy*2-dx*2))
(setq err (+ err dy*2)))
(setq x0 (+ x0 xdirection))
(dot x0 y0))))

(defun octant1or2 (x0 y0 dx dy xdirection) ; |dx|<dy
(let* ((dx*2 (* dx 2))
(dx*2-dy*2 (- dx*2 (round (* dy 2))))
(err (- dx*2 (round dy))))
(dot x0 y0)
(while (>= (setq dy (1- dy)) 0)
(if (>= err 0)
(setq x0 (+ x0 xdirection)
err (+ err dx*2-dy*2))
(setq err (+ err dx*2)))
(setq y0 (1+ y0))
(dot x0 y0))))

(defun line (x0 y0 x1 y1)
(let (dx dy temp)
(when (> y0 y1)
(setq temp y0
y0 y1
y1 temp
temp x0
x0 x1
x1 temp))
(setq dx (- x1 x0)
dy (- y1 y0))
(if (> dx 0)
(if (> dx dy)
(octant0or3 x0 y0 dx dy 1)
(octant1or2 x0 y0 dx dy 1))
(setq dx (- dx))
(if (> dx dy)
(octant0or3 x0 y0 dx dy -1)
(octant1or2 x0 y0 dx dy -1)))))

(defun dot (x y)
(goto-line y)
(forward-char x)
(delete-char 1)
(insert ?\*))

(defun drawing-buffer ()
(with-current-buffer (get-buffer-create "*drawing-buffer*")
(erase-buffer)
(dotimes (i 30)
(insert (make-string 70 ?\.) ?\n))
(display-buffer "*drawing-buffer*")))

(drawing-buffer)
(with-current-buffer "*drawing-buffer*"
(line 13 21 32 5)
(line 13 21 56 21)
(line 32 5 56 21)
(line 9 10 33 26)
(line 9 10 58 10)
(line 33 26 58 10))

Name: Anonymous 2014-10-05 3:00

>>6
fuck off, r-tard, serious programming (as in low-level) is all imperative.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List