added bitmap/url to 2htdp/image
This commit is contained in:
parent
c12d52f21b
commit
a20809c347
|
@ -128,7 +128,8 @@ and they all have good sample contracts. (It is amazing what we can do with kids
|
|||
step-count?
|
||||
save-image
|
||||
|
||||
freeze)
|
||||
freeze
|
||||
bitmap/url)
|
||||
|
||||
(provide bitmap
|
||||
empty-image)
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
racket/math
|
||||
(for-syntax racket/base
|
||||
racket/list)
|
||||
lang/posn)
|
||||
lang/posn
|
||||
net/url)
|
||||
|
||||
;; for testing
|
||||
; (require racket/gui/base)
|
||||
|
@ -98,12 +99,6 @@
|
|||
; ;;
|
||||
|
||||
|
||||
;; bitmap : string -> image
|
||||
;; gets one of the bitmaps that comes with drracket, scales it down by 1/8 or something
|
||||
;; so that later scaling /translation/whatever will look reasonable.
|
||||
;; (the error message for a bad argument will list all of the currently installed example images;
|
||||
;; we may want to have some way teachers can stick new ones in there)
|
||||
|
||||
;; scale : number image -> image
|
||||
(define/chk (scale factor image)
|
||||
(scale-internal factor factor image))
|
||||
|
@ -1273,6 +1268,16 @@
|
|||
;; the rotate does a coercion to a 2htdp/image image
|
||||
(rotate 0 (make-object image-snip% (make-object bitmap% arg 'unknown/mask))))
|
||||
|
||||
(define/chk (bitmap/url string)
|
||||
;; the rotate does a coercion to a 2htdp/image image
|
||||
(rotate
|
||||
0
|
||||
(call/input-url (string->url string)
|
||||
get-pure-port
|
||||
(λ (port)
|
||||
(make-object bitmap% port 'unknown #f #t)))))
|
||||
|
||||
|
||||
(define/chk (image->color-list image)
|
||||
(let* ([w (image-width image)]
|
||||
[h (image-height image)]
|
||||
|
@ -1443,6 +1448,7 @@
|
|||
color-list->bitmap
|
||||
|
||||
bitmap
|
||||
bitmap/url
|
||||
|
||||
swizzle
|
||||
|
||||
|
|
|
@ -1110,6 +1110,14 @@ more expensive than with the other shapes.
|
|||
(bitmap icons/b-run.png)]
|
||||
}
|
||||
|
||||
@defproc[(bitmap/url [url string?]) image?]{
|
||||
Goes out on the web and downloads the image at @racket[url].
|
||||
|
||||
Downloading the image happens each time this function is called, so
|
||||
you may find it simpler to download the image once with a browser
|
||||
and then paste it into your program or download it and use @racket[bitmap].
|
||||
}
|
||||
|
||||
@defproc[(image->color-list [image image?]) (listof color?)]{
|
||||
Returns a list of colors that correspond to the colors in the
|
||||
image, reading from left to right, top to bottom.
|
||||
|
|
Loading…
Reference in New Issue
Block a user