diff options
author | Colin Okay <okay@toyful.space> | 2022-07-17 19:37:50 -0500 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-07-17 19:37:50 -0500 |
commit | 3e85c0806e4ab69fdecf9d2266656c333c17a526 (patch) | |
tree | a1afcb441738d8955f66c5c77155b61721af502f /examples/11-canvas-geometry.lisp | |
parent | 2c87167d61f5e705353aa61bb008687c51a51b8b (diff) |
[add] path drwing and filling to canvas
Diffstat (limited to 'examples/11-canvas-geometry.lisp')
-rw-r--r-- | examples/11-canvas-geometry.lisp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/examples/11-canvas-geometry.lisp b/examples/11-canvas-geometry.lisp index 1147ed9..8565eb3 100644 --- a/examples/11-canvas-geometry.lisp +++ b/examples/11-canvas-geometry.lisp @@ -8,11 +8,16 @@ (defclass geo-demo (ww:application) ()) +(ww:defhandler quit + (ww::on-keydown (app scancode) + (when (eql :scancode-q scancode) + (ww::stop)))) + (defmethod ww:boot ((app geo-demo)) (let ((canvas (make-instance 'ww:canvas - :pixel-width 500 - :pixel-height 500))) + :pixel-width 200 + :pixel-height 200))) ;; stretch canvas over the whole app (setf (ww:width canvas) (ww::application-width app) (ww:height canvas) (ww::application-height app)) @@ -21,12 +26,45 @@ (ww:add-unit app canvas) ;; draw a circle - (ww::with-grid-circle (x y) (50 50 30) + (ww::with-grid-circle (x y) (150 50 30 :interiorp t) (ww::with-pixel (r g b a) (ww::pixel canvas x y) (setf r (mod (* x y) 255) g x b y))) - + ;; draw a bunch of circles + (loop + for cx from 0 to 50 by 5 + for cy from 0 to 50 by 5 do + (ww::with-grid-circle (x y) ((+ 100 cx) (+ 100 cy) 10) + (ww::with-pixel (r g b a) (ww::pixel canvas x y) + (setf r (mod (* x y) 256) + g (mod (* x x) 256) + b (mod (* y x) 256))))) + + ;; draw a random pentagonal thing + (let ((path + (loop repeat 7 + collect (list (+ 10 (random 80)) + (+ 10 (random 80)))))) + (ww::with-grid-path (x y) (path :autoclosep t :interiorp t) + (ww::with-pixel (r g b a) (ww::pixel canvas x y) + (setf r (mod y 256) + g (mod x 256) + b (mod (* x y) 256))))) + ;; blit the canvas - (ww::blit canvas))) + (ww::blit canvas) + + ;; quit handler + (ww:add-handler app #'quit) + (ww:add-handler canvas #'quit))) + +(defun start () + (ww::start + (make-instance + 'geo-demo + :fps 10 + :width 500 + :height 500 + :title "Pixels Geometry"))) |