add a little more discussion based on comment from mailing list
This commit is contained in:
parent
79c6a2b1e5
commit
e256a396ba
|
@ -17,28 +17,42 @@
|
||||||
@(interaction-eval #:eval img-eval (require 2htdp/image))
|
@(interaction-eval #:eval img-eval (require 2htdp/image))
|
||||||
@(interaction-eval #:eval img-eval (require lang/posn))
|
@(interaction-eval #:eval img-eval (require lang/posn))
|
||||||
|
|
||||||
@(interaction-eval
|
@(img-eval '(define extra-margin (make-parameter 0)))
|
||||||
#:eval
|
|
||||||
img-eval
|
@(img-eval
|
||||||
(let ([ce (current-eval)])
|
`(let ([ce (current-eval)])
|
||||||
(define (adjust-image i)
|
(define (adjust-image exp i)
|
||||||
(if (image? i)
|
(if (image? i)
|
||||||
|
(let ([em (extra-margin)])
|
||||||
(overlay/xy i
|
(overlay/xy i
|
||||||
0 0
|
(- em) (- em)
|
||||||
(rectangle
|
(rectangle
|
||||||
(+ (image-width i) 1)
|
(+ (image-width i) 1 em em)
|
||||||
(+ (image-height i) 1)
|
(+ (image-height i) 1 em em)
|
||||||
'solid
|
'solid
|
||||||
(color 0 0 0 0)))
|
(color 255 0 0 0))))
|
||||||
i))
|
i))
|
||||||
(current-eval
|
(current-eval
|
||||||
(λ (exp)
|
(λ (exp)
|
||||||
(adjust-image (ce exp))))))
|
(adjust-image exp (ce exp))))))
|
||||||
|
|
||||||
@(define-syntax-rule
|
@(define-syntax-rule
|
||||||
(image-examples exp ...)
|
(image-examples exp ...)
|
||||||
(examples #:eval img-eval exp ...))
|
(examples #:eval img-eval exp ...))
|
||||||
|
|
||||||
|
@(define-syntax-rule
|
||||||
|
(image-interaction exp ...)
|
||||||
|
(interaction #:eval img-eval exp ...))
|
||||||
|
|
||||||
|
@(define-syntax-rule
|
||||||
|
(image-interaction/margin num exp)
|
||||||
|
(begin
|
||||||
|
(racketinput exp)
|
||||||
|
(img-eval '(extra-margin num))
|
||||||
|
(interaction-eval-show #:eval img-eval exp)
|
||||||
|
(img-eval '(extra-margin 0))))
|
||||||
|
|
||||||
|
|
||||||
@teachpack["image"]{Images}
|
@teachpack["image"]{Images}
|
||||||
|
|
||||||
@(define mode/color-text
|
@(define mode/color-text
|
||||||
|
@ -1636,10 +1650,10 @@ Specifically, the upper and left-hand lines around the square are within
|
||||||
the bounding box, but the lower and right-hand lines are just outside.
|
the bounding box, but the lower and right-hand lines are just outside.
|
||||||
|
|
||||||
This kind of rectangle is useful when putting rectangles next to each other
|
This kind of rectangle is useful when putting rectangles next to each other
|
||||||
and avoiding extra thick lines on the interior. For example, imagine
|
and avoiding extra thick lines on the interior. For example, consider
|
||||||
building a grid like this:
|
building a grid like this:
|
||||||
|
|
||||||
@image-examples[(let* ([s (rectangle 20 20 "outline" "black")]
|
@image-interaction[(let* ([s (rectangle 20 20 "outline" "black")]
|
||||||
[r (beside s s s s s s)])
|
[r (beside s s s s s s)])
|
||||||
(above r r r r r r))]
|
(above r r r r r r))]
|
||||||
|
|
||||||
|
@ -1660,19 +1674,25 @@ that is not possible. Instead, the same pixels are lit up as with the 2 pixel wi
|
||||||
with only 1/2 of the intensity of the color. So a 1 pixel wide black @racket[pen] object draws
|
with only 1/2 of the intensity of the color. So a 1 pixel wide black @racket[pen] object draws
|
||||||
a 2 pixel wide outline, but in gray.
|
a 2 pixel wide outline, but in gray.
|
||||||
|
|
||||||
When combining pens and cropping, we can make a rectangle that has a line that is one pixel
|
@image-interaction/margin[2
|
||||||
wide, but where the line is drawn entirely within the rectangle
|
(rectangle
|
||||||
|
20 20 "outline"
|
||||||
|
(make-pen "black" 1 "solid" "round" "round"))]
|
||||||
|
|
||||||
@image-examples[(crop
|
When combining pens and cropping, we can make a rectangle that has a line that is one pixel
|
||||||
|
wide, but where the line is drawn entirely within the rectangle. This rectangle has a two-pixel wide
|
||||||
|
black pen, but we can crop out the outer portion of the pen.
|
||||||
|
|
||||||
|
@image-interaction[(crop
|
||||||
0 0 20 20
|
0 0 20 20
|
||||||
(rectangle
|
(rectangle
|
||||||
20 20 "outline"
|
20 20 "outline"
|
||||||
(make-pen "black" 2 "solid" "round" "round")))]
|
(make-pen "black" 2 "solid" "round" "round")))]
|
||||||
|
|
||||||
and we can use that to build a grid now too, but this grid has doubled lines on the
|
Using that we can build a grid now too, but this grid has doubled lines on the
|
||||||
interior.
|
interior.
|
||||||
|
|
||||||
@image-examples[(let* ([s (crop
|
@image-interaction[(let* ([s (crop
|
||||||
0 0 20 20
|
0 0 20 20
|
||||||
(rectangle
|
(rectangle
|
||||||
20 20 "outline"
|
20 20 "outline"
|
||||||
|
@ -1686,6 +1706,18 @@ exceed its bounding box. Specifically, this kind of drawing is used
|
||||||
by @racket[frame] and @racket[empty-scene] so that the extra drawn pixels
|
by @racket[frame] and @racket[empty-scene] so that the extra drawn pixels
|
||||||
are not lost if the image is later clipped to its bounding box.
|
are not lost if the image is later clipped to its bounding box.
|
||||||
|
|
||||||
|
When using @racket[image->color-list] with outline shapes, the results
|
||||||
|
can be surprising for the same reasons. For example, a
|
||||||
|
2x2 black, outline rectangle consists of nine black pixels, as discussed above,
|
||||||
|
but since @racket[image->color-list] only returns the pixels that are
|
||||||
|
within the bounding box, we see only three black pixels and one white one.
|
||||||
|
|
||||||
|
@image-interaction[(image->color-list
|
||||||
|
(rectangle 2 2 "outline" "black"))]
|
||||||
|
|
||||||
|
The black pixels are (most of) the upper and left edge of the outline shape,
|
||||||
|
and the one white pixel is the pixel in the middle of the shape.
|
||||||
|
|
||||||
@;-----------------------------------------------------------------------------
|
@;-----------------------------------------------------------------------------
|
||||||
@section{Exporting Images to Disk}
|
@section{Exporting Images to Disk}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user