aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/12-canvas-drawing-language.lisp14
-rw-r--r--src/canvas-language.lisp11
2 files changed, 17 insertions, 8 deletions
diff --git a/examples/12-canvas-drawing-language.lisp b/examples/12-canvas-drawing-language.lisp
index bece8c8..b4a621b 100644
--- a/examples/12-canvas-drawing-language.lisp
+++ b/examples/12-canvas-drawing-language.lisp
@@ -62,14 +62,16 @@
;; 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)))
+ (loop for a from 0 to (* 2 pi) by (/ (* 2 pi) petals)
+ for ls = (list (list (* r (sin (- a psw)))
(* r (cos (- a psw))))
(list (* r (sin (+ a psw)))
(* r (cos (+ a psw))))
(list 0 0))
- 12))))
+ do
+ (ww::fill-rel-bezier ls 12)
+ (ww::with-pen (:color (list 0 0 0 255))
+ (ww::stroke-rel-bezier ls 12)))))
(defun draw-stuff (canvas)
(ww::with-canvas canvas
@@ -86,10 +88,6 @@
;; draw a flower
(flower 28))
-
-
- ;; draw a bunch of triangles
- (ww::canvas-pen-width 1)
(dotimes (x 50)
(when (evenp x)
(triangle-at 30 (+ 250 x))))))
diff --git a/src/canvas-language.lisp b/src/canvas-language.lisp
index 610c8e0..05cddfd 100644
--- a/src/canvas-language.lisp
+++ b/src/canvas-language.lisp
@@ -196,3 +196,14 @@ saved by WITH-PEN-STATE"
(stroke-bezier (cons *current-pen-position*
(rel-to-current-pos rel-control-points))
curve-samples))
+
+(defun fill-bezier (control-pts &optional (curve-samples 10))
+ (let (path)
+ (with-grid-bezier (x y) (control-pts :count curve-samples)
+ (push (list x y) path))
+ (fill-path (reverse path))))
+
+(defun fill-rel-bezier (rel-control-points &optional (curve-samples 10))
+ (fill-bezier (cons *current-pen-position*
+ (rel-to-current-pos rel-control-points))
+ curve-samples))