fix the gradient example code in the docs.

Things wrong:

 - indentation
 - the dc callback didn't reset the dc state
   (this is okay if you only use the pict
    in the interactions window in drracket,
    because drracket protects itself, but it
    is not okay if you use them in slideshow
    or something)
 - the dc callback didn't use the 'dx' and 'dy'
   arguments properly
   (you could see this going wrong if you put
    two of the picts together in an hc-append
    and looked at the compound pict in the
    interactions window)
This commit is contained in:
Robby Findler 2012-08-10 12:15:37 -05:00
parent aa6ed4d736
commit a799985951
2 changed files with 82 additions and 40 deletions

View File

@ -34,29 +34,51 @@ points in between.
@examples[
#:eval class-eval
(define no-pen (make-object pen% "BLACK" 1 'transparent))
(define brush-grad (new brush% [gradient
(new linear-gradient%
[x0 300] [y0 250] [x1 500] [y1 50]
[stops
(list (list 0 (make-object color% 255 0 0))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 0 0 255)))])]))
(define ellipse-brush
(new brush%
[gradient
(new linear-gradient%
[x0 0]
[y0 200]
[x1 200]
[y1 00]
[stops
(list (list 0 (make-object color% 255 0 0))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 0 0 255)))])]))
(define brush-grad2 (new brush% [gradient
(make-object linear-gradient%
50 150 250 150
(list (list 0 (make-object color% 255 0 0))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 0 0 255))))]))
(dc (lambda (dc x y)
(send dc set-pen no-pen)
(send dc set-brush brush-grad2)
(send dc draw-ellipse 50 50 200 200)
(send dc set-brush brush-grad)
(send dc draw-rectangle 300 50 200 200)) 550 300)
(define rectangle-brush
(new brush%
[gradient
(new linear-gradient%
[x0 0]
[y0 100]
[x1 100]
[y1 0]
[stops
(list (list 0 (make-object color% 255 0 0))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 0 0 255)))])]))
(dc
(λ (dc dx dy)
(define old-pen (send dc get-pen))
(define old-brush (send dc get-brush))
(define-values (ox oy) (send dc get-origin))
(send dc set-pen "black" 1 'transparent)
(send dc set-brush ellipse-brush)
(send dc set-origin (+ ox dx 50) (+ oy dy 50))
(send dc draw-ellipse 0 0 200 200)
(send dc set-brush rectangle-brush)
(send dc set-origin (+ ox dx 300) (+ oy dy 50))
(send dc draw-rectangle 0 0 200 200)
(send dc set-pen old-pen)
(send dc set-brush old-brush)
(send dc set-origin ox oy))
550 300)
]}

View File

@ -34,27 +34,47 @@ correspond to circles in between.
@examples[
#:eval class-eval
(define no-pen (make-object pen% "BLACK" 1 'transparent))
(define brush-grad (new brush% [gradient (new radial-gradient%
[x0 400] [y0 150] [r0 10] [x1 400] [y1 150] [r1 100]
[stops
(list (list 0 (make-object color% 255 0 0))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 0 0 255)))])]))
(define ellipse-brush
(new brush%
[gradient
(new radial-gradient%
[x0 100] [y0 100] [r0 0]
[x1 100] [y1 100] [r1 100]
[stops
(list (list 0 (make-object color% 0 0 255))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 255 0 0)))])]))
(define brush-grad2 (new brush% [gradient
(make-object radial-gradient% 150 150 0 150 150 100
(list (list 0 (make-object color% 0 0 255))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 255 0 0))))]))
(define rectangle-brush
(new brush%
[gradient
(new radial-gradient%
[x0 100] [y0 100] [r0 10]
[x1 100] [y1 100] [r1 100]
[stops
(list (list 0 (make-object color% 255 0 0))
(list 0.5 (make-object color% 0 255 0))
(list 1 (make-object color% 0 0 255)))])]))
(dc (lambda (dc x y)
(send dc set-pen no-pen)
(send dc set-brush brush-grad2)
(send dc draw-ellipse 50 50 200 200)
(send dc set-brush brush-grad)
(send dc draw-rectangle 300 50 200 200)) 550 300)
(dc
(λ (dc dx dy)
(define old-pen (send dc get-pen))
(define old-brush (send dc get-brush))
(define-values (ox oy) (send dc get-origin))
(send dc set-pen "black" 1 'transparent)
(send dc set-brush ellipse-brush)
(send dc set-origin (+ ox dx 50) (+ oy dy 50))
(send dc draw-ellipse 0 0 200 200)
(send dc set-origin (+ ox dx 300) (+ oy dy 50))
(send dc set-brush rectangle-brush)
(send dc draw-rectangle 0 0 200 200)
(send dc set-pen old-pen)
(send dc set-brush old-brush)
(send dc set-origin ox oy))
550 300)
]}
@defmethod[(get-circles)