diff options
-rw-r--r-- | src/interactive/canvas.lisp | 2 | ||||
-rw-r--r-- | src/utils.lisp | 28 |
2 files changed, 15 insertions, 15 deletions
diff --git a/src/interactive/canvas.lisp b/src/interactive/canvas.lisp index 256348e..e8bdc39 100644 --- a/src/interactive/canvas.lisp +++ b/src/interactive/canvas.lisp @@ -89,7 +89,7 @@ e.g., drawing a line in a particular color." (let ((pxs (gensym))) `(let ((,pxs ,pixels)) - (with-line (,x ,y) (,start-x ,start-y) (,end-x ,end-y) + (with-grid-line (,x ,y) (,start-x ,start-y) (,end-x ,end-y) (with-pixel (,r ,g ,b ,a) (pixel ,pxs ,x ,y) ,@body))))) diff --git a/src/utils.lisp b/src/utils.lisp index 9e1e46b..4037b7a 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -116,22 +116,22 @@ the path." (setf ,@clauses)))) -(defmacro with-line +(defmacro with-grid-line ((x y) (start-x start-y) (end-x end-y) &body body) "Execute BODY for X and Y assigned to integer values in a line connecting the integer point START-X , START-Y and END-X, END-Y. " (with-gensyms (sx sy ex ey distance step progress xdiff ydiff) - `(let* ((,sx ,start-x) - (,sy ,start-y) - (,ex ,end-x) - (,ey ,end-y) - (,xdiff (- ,ex ,sx)) - (,ydiff (- ,ey ,sy)) - (,distance (max (abs ,xdiff) (abs ,ydiff)))) - (loop for ,step from 0 to ,distance - for ,progress = (if (zerop ,distance) 0.0 (/ ,step ,distance)) - for ,x = (round (+ ,start-x (* ,progress ,xdiff))) - for ,y = (round (+ ,start-y (* ,progress ,ydiff))) - do (progn ,@body))))) - + `(loop + with ,sx = ,start-x + with ,sy = ,start-y + with ,ex = ,end-x + with ,ey = ,end-y + with ,xdiff = (- ,ex ,sx) + with ,ydiff = (- ,ey, sy) + with ,distance = (max (abs ,xdiff) (abs ,ydiff)) + for ,step from 0 to ,distance + for ,progress = (if (zerop ,distance) 0.0 (/ ,step ,distance)) + for ,x = (round (+ ,start-x (* ,progress ,xdiff))) + for ,y = (round (+ ,start-y (* ,progress ,ydiff))) + do (progn ,@body)))) |