aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/12-canvas-drawing-language.lisp31
1 files changed, 24 insertions, 7 deletions
diff --git a/examples/12-canvas-drawing-language.lisp b/examples/12-canvas-drawing-language.lisp
index 24008c2..bece8c8 100644
--- a/examples/12-canvas-drawing-language.lisp
+++ b/examples/12-canvas-drawing-language.lisp
@@ -19,6 +19,7 @@
(draw-stuff canvas)
(ww::blit canvas)))
+;; draw a triangle, each side is a different color
(defun triangle-at (x y)
(ww::move-to x y)
(ww::canvas-pen-color (list 0 200 200 255))
@@ -28,28 +29,39 @@
(ww::canvas-pen-color (list 0 200 0 255))
(ww::stroke-rel -100 -100))
+
+;; draw a filled triangle using the current pen
(defun filled-triangle-at (x y)
(ww::move-to x y)
(ww::fill-rel-path
'((100 100)
(100 -100))))
+;; a pen function - gets more blue the closer x y is to 0 0
(defun lower-the-bluer (x y)
(list (* 256 (/ x 500))
(* 256 (/ y 500))
255
255))
+;; a pen function - makes a plaid like pattern
(defun plaid1 (x y)
(list (mod (* x x) 256)
(mod (* y y) 256)
(mod (* x y) 256)
255))
+;; draws a "flower" like pinwheel using bezier curves
(defun flower (&optional (petals 5))
(ww::canvas-pen-width 1)
- (let ((r (sqrt (+ (* 25 25) (* 100 100))))
- (psw (* pi 0.08)))
+ (let ((r ; radius
+ (sqrt (+ (* 25 25) (* 100 100))))
+ (psw ; petal semi-width
+ (* pi 0.08)))
+ ;; for each angle a between 0 and 2π draw a petal as a bezier
+ ;; curve. the curve uses two control points that are R away from
+ ;; the starting point and PSW radians on either side of the line
+ ;; at angle a
(loop for a from 0 to (* 2 pi) by (/ (* 2 pi) petals) do
(ww::stroke-rel-bezier
(list (list (* r (sin (- a psw)))
@@ -61,17 +73,22 @@
(defun draw-stuff (canvas)
(ww::with-canvas canvas
+ ;; set canvas color.
(ww::canvas-pen-color #'plaid1)
(filled-triangle-at 250 200)
- (ww::canvas-pen-width 2)
- ;; temporarily use a different pen
- (ww::with-pen-color #'lower-the-bluer
+ ;; temporarily use a different pen configuration
+ (ww::with-pen (:color #'lower-the-bluer :width 2)
+ ;; draw a flower stem
(ww::stroke-bezier
'((0 0) (200 120) (50 350) (200 100) (300 400))
- 12)) ;; back to plaid pen after this
+ 12)
+ ;; draw a flower
+ (flower 28))
+
+
- (flower 28)
+ ;; draw a bunch of triangles
(ww::canvas-pen-width 1)
(dotimes (x 50)
(when (evenp x)