diff --git a/collects/2htdp/image.rkt b/collects/2htdp/image.rkt index a8ca6e81ab..9ac051eee3 100644 --- a/collects/2htdp/image.rkt +++ b/collects/2htdp/image.rkt @@ -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) diff --git a/collects/2htdp/private/image-more.rkt b/collects/2htdp/private/image-more.rkt index ff8fa60f0d..9a3c5c61a2 100644 --- a/collects/2htdp/private/image-more.rkt +++ b/collects/2htdp/private/image-more.rkt @@ -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 diff --git a/collects/teachpack/2htdp/scribblings/image.scrbl b/collects/teachpack/2htdp/scribblings/image.scrbl index c6b3964820..eb5f4e9a76 100644 --- a/collects/teachpack/2htdp/scribblings/image.scrbl +++ b/collects/teachpack/2htdp/scribblings/image.scrbl @@ -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.