added overlay/pinhole and underlay/pinhole

This commit is contained in:
Robby Findler 2010-09-07 09:19:23 -05:00
parent 90cf9f2183
commit 9105b92240
8 changed files with 99 additions and 2 deletions

View File

@ -130,6 +130,8 @@ and they all have good sample contracts. (It is amazing what we can do with kids
center-pinhole
pinhole-x
pinhole-y
overlay/pinhole
underlay/pinhole
make-color
make-pen pen

View File

@ -156,6 +156,22 @@
(let ([imgs (reverse (list* image image2 image3))])
(overlay/internal x-place y-place (car imgs) (cdr imgs))))
(define/chk (overlay/pinhole image1 image2 . image3)
(overlay/internal 'pinhole 'pinhole
(maybe-center-pinhole image1)
(map maybe-center-pinhole (cons image2 image3))))
(define/chk (underlay/pinhole image1 image2 . image3)
(let ([imgs (map maybe-center-pinhole (reverse (list* image1 image2 image3)))])
(overlay/internal 'pinhole 'pinhole
(car imgs)
(cdr imgs))))
(define (maybe-center-pinhole img)
(if (send img get-pinhole)
img
(center-pinhole img)))
(define (overlay/internal x-place y-place fst rst)
(let loop ([fst fst]
[rst rst])
@ -1384,6 +1400,8 @@
pinhole-y
clear-pinhole
center-pinhole
overlay/pinhole
underlay/pinhole
build-color/make-color
build-color/color

View File

@ -36,6 +36,42 @@
(above r r r r r r))
'image
"245380940d6-1.png")
(list
'(let* ((t (triangle 40 "solid" "orange"))
(w (image-width t))
(h (image-height t)))
(clear-pinhole
(overlay/pinhole
(put-pinhole (/ w 2) 0 t)
(put-pinhole w h t)
(put-pinhole 0 h t))))
'image
"1847b22ee5c.png")
(list
'(underlay/pinhole
(put-pinhole 25 10 (ellipse 100 50 "solid" "red"))
(put-pinhole 75 40 (ellipse 100 50 "solid" "blue")))
'image
"1648582961a.png")
(list
'(let ((petal (put-pinhole 20 20 (ellipse 100 40 "solid" "purple"))))
(clear-pinhole
(overlay/pinhole
(circle 30 "solid" "yellow")
(rotate (* 60 0) petal)
(rotate (* 60 1) petal)
(rotate (* 60 2) petal)
(rotate (* 60 3) petal)
(rotate (* 60 4) petal)
(rotate (* 60 5) petal))))
'image
"31011b92fc.png")
(list
'(overlay/pinhole
(put-pinhole 25 10 (ellipse 100 50 "solid" "red"))
(put-pinhole 75 40 (ellipse 100 50 "solid" "blue")))
'image
"d2d7809e7e.png")
(list '(pinhole-y (center-pinhole (rectangle 10 10 "solid" "red"))) 'val '5)
(list '(pinhole-x (center-pinhole (rectangle 10 10 "solid" "red"))) 'val '5)
(list

View File

@ -1290,8 +1290,9 @@ in the image. The pinhole can then be used to facilitate overlaying images by
lining them up on the their pinholes.
When an image has a pinhole, the pinhole
is drawn with crosshairs drawn across the image.
The crosshairs are drawn with a two one pixel wide black lines and two one pixel wide white lines,
is drawn with crosshairs on the image.
The crosshairs are drawn with a two one pixel wide black lines (one horizontal and one vertical)
and two one pixel wide white lines,
where the black lines is drawn .5 pixels to the left and above the pinhole, and the
white lines are drawn .5 pixels to the right and below the pinhole.
Accordingly, when the pixel is on an integral coordinate, then black and white lines all
@ -1325,6 +1326,46 @@ then the scene argument's pinhole is preserved.
Removes a pinhole from @racket[image] (if the image has a pinhole).
}
@defproc[(overlay/pinhole [i1 image?] [i2 image?] [is image?] ...) image?]{
Overlays all of the image arguments on their pinholes. If any of the
arguments do not have pinholes, then the center of the image is used instead.
@image-examples[(overlay/pinhole
(put-pinhole 25 10 (ellipse 100 50 "solid" "red"))
(put-pinhole 75 40 (ellipse 100 50 "solid" "blue")))
(let ([petal (put-pinhole
20 20
(ellipse 100 40 "solid" "purple"))])
(clear-pinhole
(overlay/pinhole
(circle 30 "solid" "yellow")
(rotate (* 60 0) petal)
(rotate (* 60 1) petal)
(rotate (* 60 2) petal)
(rotate (* 60 3) petal)
(rotate (* 60 4) petal)
(rotate (* 60 5) petal))))]
}
@defproc[(underlay/pinhole [i1 image?] [i2 image?] [is image?] ...) image?]{
Underlays all of the image arguments on their pinholes. If any of the
arguments do not have pinholes, then the center of the image is used instead.
@image-examples[(underlay/pinhole
(put-pinhole 25 10 (ellipse 100 50 "solid" "red"))
(put-pinhole 75 40 (ellipse 100 50 "solid" "blue")))
(let* ([t (triangle 40 "solid" "orange")]
[w (image-width t)]
[h (image-height t)])
(clear-pinhole
(overlay/pinhole
(put-pinhole (/ w 2) 0 t)
(put-pinhole w h t)
(put-pinhole 0 h t))))]
}
@section[#:tag "nitty-gritty"]{The nitty gritty of pixels, pens, and lines}
The image library treats coordinates as if they are in the upper-left corner

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB