aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-07-15 22:08:13 -0500
committerColin Okay <colin@cicadas.surf>2022-07-15 22:08:13 -0500
commit55acc817ad919c47de39e0febe8630304792793f (patch)
treeaead231f6bacd2d0399018ddf9025433c0870d44 /src
parent5654b8b4c30fd783dd1d1d1eb716e4f21c0ac83e (diff)
[example] tweaking canvas example
Diffstat (limited to 'src')
-rw-r--r--src/interactive/canvas.lisp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/interactive/canvas.lisp b/src/interactive/canvas.lisp
index 2fa341c..ce7829b 100644
--- a/src/interactive/canvas.lisp
+++ b/src/interactive/canvas.lisp
@@ -12,6 +12,9 @@
:element-type 'unsigned-byte
:initial-element 255))))
+(defun pixel-offset (x y pixels)
+ (* 4 (+ x (* y (pixel-width pixels)))))
+
(let ((cached-pixel))
(defun pixel (pixels x y &optional (use-cached t))
"When USE-CACHED is NIL, return a fresh array displaced to
@@ -50,8 +53,7 @@
(,a (aref ,pixel-var 3)))
,@body))))
-(defun pixel-offset (x y pixels)
- (* 4 (+ x (* y (pixel-width pixels)))))
+
(defmacro with-pixels-rect ((x y r g b a) (pixels &key left right top bottom) &body body)
"Executes BODY on all pixels in the box bounded by LEFT RIGHT TOP and BOTTOM of PIXELS.
@@ -73,11 +75,15 @@
(loop for ,x from (if ,lv ,lv 0) below (if ,rv ,rv (pixel-width ,pxs)) do
(loop for ,y from (if ,bv ,bv 0) below (if ,tv ,tv (pixel-height ,pxs))
do (progn
- (setf ,px (adjust-array ,px 4
- :displaced-to (pixels-data ,pxs)
- :displaced-index-offset (pixel-offset ,x ,y ,pxs)))
+ (setf ,px (adjust-array ,px 4
+ :displaced-to (pixels-data ,pxs)
+ :displaced-index-offset (pixel-offset ,x ,y ,pxs)))
,@body)))))))
+(defun clear-canvas (canvas &key (r 0) (g 0) (b 0) (a 255))
+ (with-pixels-rect (x y pr pg pb pa) (canvas)
+ (setf pr r pg g pb b pa a)))
+
(defmacro with-pixels-line ((x y r g b a) (pixels start-x start-y end-x end-y) &body body)
"A convenience macro for doing something to a whole line of pixels -
e.g., drawing a line in a particular color."