diff --git a/pitfall/pitfall/test/test2.rkt b/pitfall/pitfall/test/test2.rkt index 7f4c45bf..fe6ebf64 100644 --- a/pitfall/pitfall/test/test2.rkt +++ b/pitfall/pitfall/test/test2.rkt @@ -40,18 +40,18 @@ [stroke] [restore]) - #| - ;; filled circle (send* doc [save] [translate 400 0] [circle 100 50 50] [lineWidth 3] - [fillOpacity 0 [8]] + [fillOpacity 0.8] [fillAndStroke "red" "#900"] [restore]) + #| + (send* doc [translate 0 200]) ;; these examples are easier to see with a large line width diff --git a/pitfall/pitfall/vector.rkt b/pitfall/pitfall/vector.rkt index 69781702..e98e792d 100644 --- a/pitfall/pitfall/vector.rkt +++ b/pitfall/pitfall/vector.rkt @@ -12,8 +12,9 @@ save restore closePath - lineTo + dash moveTo + lineTo bezierCurveTo quadraticCurveTo ellipse @@ -56,6 +57,23 @@ (send this addContent "h")) +(define/contract (dash this length [options (mhash)]) + (((or/c number? (listof number?) #f)) (hash?) . ->*m . object?) + (cond + [length + (cond + [(list? length) + (send this addContent + (format "[~a] ~a d" + (string-join (map number length) " ") + (hash-ref options 'phase 0)))] + [else + (define space (hash-ref options 'space length)) + (define phase (hash-ref options 'phase 0)) + (send this addContent (format "[~a ~a] ~a d" (number length) (number space) (number phase)))])] + [else this])) + + (define/contract (moveTo this x y) (number? number? . ->m . object?) (send this addContent (format "~a ~a m" x y))) @@ -104,12 +122,13 @@ (define/contract (polygon this . points) (() () #:rest (listof (list/c number? number?)) . ->*m . object?) - (when (pair? points) - (match-define (cons first-pt other-pts) points) - (apply moveTo this first-pt) - (for ([pt (in-list other-pts)]) - (apply lineTo this pt)) - (closePath this))) + (cond + [(pair? points) + (apply moveTo this (car points)) + (for ([pt (in-list (cdr points))]) + (apply lineTo this pt)) + (closePath this)] + [else this])) (define/contract (path this path-data)