diff options
author | Colin Okay <colin@cicadas.surf> | 2022-07-19 08:21:45 -0500 |
---|---|---|
committer | Colin Okay <colin@cicadas.surf> | 2022-07-19 08:21:45 -0500 |
commit | ba248e490e1ab67e124b02e765e0ee3ec7a3dd45 (patch) | |
tree | 208b4caae4d9505df0f11899ecf3a6c56f0002d4 /examples/11-canvas-geometry.lisp | |
parent | 615c08f0f8fabd504b2bb076410d57dde7cfe34a (diff) |
[example] fiddling
Diffstat (limited to 'examples/11-canvas-geometry.lisp')
-rw-r--r-- | examples/11-canvas-geometry.lisp | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/examples/11-canvas-geometry.lisp b/examples/11-canvas-geometry.lisp index 7103663..c144c10 100644 --- a/examples/11-canvas-geometry.lisp +++ b/examples/11-canvas-geometry.lisp @@ -13,6 +13,56 @@ (when (eql :scancode-q scancode) (ww::stop)))) +(ww:defhandler clear-and-draw + (ww::on-perframe (canvas time) + (ww::clear-canvas canvas) + (draw-stuff canvas time) + (ww::blit canvas))) + +(defun draw-stuff (canvas &optional time) + ;; draw a circle + (ww::with-grid-circle (x y) (350 100 90 :interiorp t) + (ww::with-pixel (r g b a) (ww::pixel canvas x y) + (setf r (mod (* 3 x y time) 256) + g (mod x 256) + b (mod y 256)))) + + ;; draw a bunch of circles + (loop + for cx from 0 to 50 + for cy from 0 to 50 do + (ww::with-grid-circle (x y) ((+ 300 cx) (+ 300 cy) 80) + (ww::with-pixel (r g b a) (ww::pixel canvas x y) + (setf r (mod (* x y) 256) + g (mod time 256) + b (mod (* y x) 256))))) + + ;; draw a random thing + (let ((path + (loop repeat 7 + collect (list (+ 10 (random 240)) + (+ 10 (random 240)))))) + (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 (* 2 y) 256) + g (mod (* 3 x) 256) + b (mod (* x y) 256))))) + + (let ((control-points + `((100 250) + (,(+ (mod time 20) -10 -100) 490) + (,(+ (mod time 20) -10 300) 490) + (100 250))) + (path nil)) + ;; collect the points along the curve + (ww::with-grid-bezier (x y) (control-points :count 16) + (push (list x y) path)) + + ;; and then treat them as a closed path, which is filled. + (ww::with-grid-path (x y) (path :interiorp t) + (ww::with-pixel (r g b a) (ww::pixel canvas x y) + (setf r 200 b 120 g 30))))) + (defmethod ww:boot ((app geo-demo)) (let ((canvas (make-instance 'ww:canvas @@ -25,51 +75,8 @@ ;; add it to the display tree (ww:add-unit app canvas) - (ww::with-pixels-rect (x y r g b a) (canvas) - (ww::setf-many r g b 0)) - - ;; draw a circle - (ww::with-grid-circle (x y) (350 100 90 :interiorp t) - (ww::with-pixel (r g b a) (ww::pixel canvas x y) - (setf r (mod (* 3 x y) 256) - g (mod (+ x x) 256) - b (mod (* y y) 256)))) - - ;; draw a bunch of circles - (loop - for cx from 0 to 50 - for cy from 0 to 50 do - (ww::with-grid-circle (x y) ((+ 300 cx) (+ 300 cy) 80) - (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 thing - (let ((path - (loop repeat 7 - collect (list (+ 10 (random 240)) - (+ 10 (random 240)))))) - (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 (* 2 y) 256) - g (mod (* 3 x) 256) - b (mod (* x y) 256))))) - - (let ((control-points - '((10 490) - (200 300) - (0 400) - (40 250)))) - (ww::with-grid-bezier (x y) (control-points :count 80) - (ww::with-grid-rect (rx ry) ((- x 2) (- y 2) (+ x 2) (+ y 2)) - (ww::with-pixel (r g b a) (ww::pixel canvas rx ry) - (setf g 255))))) - - ;; blit the canvas - (ww::blit canvas) - - ;; quit handler + ;; handlers + (ww::add-handler canvas #'clear-and-draw) (ww:add-handler app #'quit) (ww:add-handler canvas #'quit))) |