Rackety 2htdp/image

This commit is contained in:
Robby Findler 2010-05-25 17:57:25 -05:00
parent 03a3270811
commit 31b507aa51
9 changed files with 192 additions and 192 deletions

View File

@ -1,4 +1,4 @@
#lang scheme/base
#lang racket/base
#|

View File

@ -1,15 +1,15 @@
#lang scheme/base
#lang racket/base
(require "../../mrlib/image-core.ss"
"img-err.ss"
scheme/match
scheme/contract
scheme/class
scheme/gui/base
racket/match
racket/contract
racket/class
racket/gui/base
htdp/error
scheme/math
(for-syntax scheme/base
scheme/list)
racket/math
(for-syntax racket/base
racket/list)
lang/posn)
(define (show-image arg [extra-space 0])
@ -92,7 +92,7 @@
;; bitmap : string -> image
;; gets one of the bitmaps that comes with drscheme, scales it down by 1/8 or something
;; 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)

View File

@ -1,4 +1,4 @@
#lang scheme/base
#lang racket/base
(provide define/chk
to-img
@ -16,13 +16,13 @@
check-mode/color-combination)
(require htdp/error
scheme/class
racket/class
lang/posn
scheme/gui/base
racket/gui/base
"../../mrlib/image-core.ss"
(prefix-in cis: "../../mrlib/cache-image-snip.ss")
(for-syntax scheme/base
scheme/list))
(for-syntax racket/base
racket/list))
;
;

View File

@ -1,10 +1,10 @@
#lang scheme
#lang racket
#|
This is a file from Guillaume that ran very slowly with the
htdp/image library; here it is used as a performance test.
Porting to #lang scheme +2htdp/image consisted of adding requires,
Porting to #lang racket +2htdp/image consisted of adding requires,
changing overlay/xy to underlay/xy, defining empty-scene, and
adding the check-expect macro (and related code).
Also added the timing code at the end.

View File

@ -1,7 +1,7 @@
#lang scheme/base
#lang racket/base
#|
;; snippet of code for experimentation
#lang scheme/gui
#lang racket/gui
(require 2htdp/image
lang/posn
(only-in lang/htdp-advanced equal~?))
@ -42,14 +42,14 @@
; "../private/img-err.ss"
"../../mrlib/private/image-core-bitmap.ss"
lang/posn
scheme/math
scheme/class
scheme/gui/base
racket/math
racket/class
racket/gui/base
rackunit
(prefix-in 1: htdp/image)
(only-in lang/htdp-advanced equal~?))
(require (for-syntax scheme/base))
(require (for-syntax racket/base))
(define-syntax (test stx)
(syntax-case stx ()
[(test a => b)

View File

@ -1,8 +1,8 @@
#lang scheme/base
#lang racket/base
#|
This library is the part of the 2htdp/image
teachpack that has to be shared between drscheme
teachpack that has to be shared between drracket
and the user's program to make copy and paste
work right.
@ -26,11 +26,11 @@ has been moved out).
|#
(require scheme/class
scheme/gui/base
scheme/math
(require racket/class
racket/gui/base
racket/math
"private/image-core-bitmap.ss"
(for-syntax scheme/base))
(for-syntax racket/base))
(define-for-syntax id-constructor-pairs '())
(define-for-syntax (add-id-constructor-pair a b)
@ -317,7 +317,7 @@ has been moved out).
(and (= (round (bb-right bb1)) (round (bb-right bb2)))
(= (round (bb-bottom bb1)) (round (bb-bottom bb2)))
(= (round (bb-baseline bb1)) (round (bb-baseline bb2)))))
(define scheme/base:read read)
(define racket/base:read read)
(define image-snipclass%
(class snip-class%
@ -331,7 +331,7 @@ has been moved out).
(and str
(with-handlers ((exn:fail:read? (λ (x) #f)))
(parse
(scheme/base:read
(racket/base:read
(open-input-string
str)))))])
(if lst

View File

@ -1,11 +1,11 @@
#lang scheme/gui
#lang racket/gui
;; Run this file is generate the images in the img/ directory,
;; picked up by image-examples from image.scrbl
(require 2htdp/image
lang/posn
scheme/runtime-path)
racket/runtime-path)
(define-runtime-path image.scrbl "image.scrbl")
(define-runtime-path img "img")
@ -105,7 +105,7 @@
(printf "\n")
(call-with-output-file "image-toc.rkt"
(λ (port)
(fprintf port "#lang scheme/base\n(provide mapping)\n")
(fprintf port "#lang racket/base\n(provide mapping)\n")
(fprintf port ";; this file is generated by image-gen.ss -- do not edit\n;; note that the file that creates this file depends on this file\n;; it is always safe to simply define (and provide) mapping as the empty list\n\n")
(pretty-print
`(define mapping (list ,@mapping))

View File

@ -1,9 +1,9 @@
#lang scheme/base
#lang racket/base
(require scribble/base
scribble/core
scribble/manual
scribble/scheme
(for-syntax scheme/base)
scribble/racket
(for-syntax racket/base)
"image-toc.ss")
(provide image-examples)
@ -15,7 +15,7 @@
(for-each (λ (exp) (printf "~s\n" (syntax->datum exp)))
(syntax->list #'(exp ...))))
#'(interleave
(list (schemeinput exp) ...)
(list (racketinput exp) ...)
(list 'exp ...))]))
(define (interleave expr-paras val-list+outputs)
@ -33,10 +33,10 @@
(let ([line (exp->line exp)])
(case (car line)
[(val)
(schemeblock #,(schemeresult #,(cadr line)))]
(racketblock #,(racketresult #,(cadr line)))]
[(image)
(let ([fn (format "2htdp/scribblings/img/~a" (cadr line))])
(schemeblock #,(image fn)))]
(racketblock #,(image fn)))]
[(missing)
(make-paragraph
error-color

View File

@ -1,11 +1,11 @@
#lang scribble/doc
@(require (for-label (only-in scheme/contract and/c or/c any/c not/c)
@(require (for-label (only-in racket/contract and/c or/c any/c not/c)
2htdp/image
(except-in lang/htdp-beginner make-posn posn? posn-x posn-y image?)
lang/posn
scheme/gui/base
(only-in scheme/base path-string?))
racket/gui/base
(only-in racket/base path-string?))
lang/posn
"shared.ss"
"image-util.ss"
@ -16,10 +16,10 @@
@(define mode/color-text
(make-splice
@list{If the @scheme[mode] is @scheme['outline] or @scheme["outline"], then the last
argument can be a @scheme[pen] struct or an @scheme[image-color?], but if the @scheme[mode]
is @scheme['solid] or @scheme["solid"], then the last argument must be an
@scheme[image-color?].}))
@list{If the @racket[mode] is @racket['outline] or @racket["outline"], then the last
argument can be a @racket[pen] struct or an @racket[image-color?], but if the @racket[mode]
is @racket['solid] or @racket["solid"], then the last argument must be an
@racket[image-color?].}))
@defmodule[#:require-form beginner-require 2htdp/image]
@ -76,7 +76,7 @@ Existing images can be rotated, scaled, and overlaid on top of each other.
image?])]{
Constructs a upward-pointing equilateral triangle.
The @scheme[side-length] argument
The @racket[side-length] argument
determines the
length of the side of the triangle.
@ -98,7 +98,7 @@ Existing images can be rotated, scaled, and overlaid on top of each other.
image?])]{
Constructs a triangle with a right angle where the two sides adjacent
to the right angle have lengths @scheme[side-length1] and @scheme[side-length2].
to the right angle have lengths @racket[side-length1] and @racket[side-length2].
@mode/color-text
@ -116,10 +116,10 @@ Existing images can be rotated, scaled, and overlaid on top of each other.
[pen-or-color (or/c pen? image-color?)])
image?])]{
Creates a triangle with two equal-length sides, of length @scheme[side-length]
where the angle between those sides is @scheme[angle]. The third
Creates a triangle with two equal-length sides, of length @racket[side-length]
where the angle between those sides is @racket[angle]. The third
leg is straight, horizontally. If the angle is less than
@scheme[180], then the triangle will point up and if the @scheme[angle]
@racket[180], then the triangle will point up and if the @racket[angle]
is more, then the triangle will point down.
@mode/color-text
@ -178,7 +178,7 @@ Existing images can be rotated, scaled, and overlaid on top of each other.
image?])]{
Constructs a four sided polygon with all equal sides and thus where opposite angles are equal to each
other. The top and bottom pair of angles is @scheme[angle] and the left and right are @scheme[(- 180 angle)].
other. The top and bottom pair of angles is @racket[angle] and the left and right are @racket[(- 180 angle)].
@mode/color-text
@ -196,7 +196,7 @@ other. The top and bottom pair of angles is @scheme[angle] and the left and righ
[outline-mode (or/c 'outline "outline")]
[pen-or-color (or/c pen? image-color?)])
image?])]{
Constructs a regular polygon with @scheme[side-count] sides.
Constructs a regular polygon with @racket[side-count] sides.
@mode/color-text
@ -213,7 +213,7 @@ other. The top and bottom pair of angles is @scheme[angle] and the left and righ
[outline-mode (or/c 'outline "outline")]
[color (or/c pen? image-color?)])
image?])]{
Constructs a star with five points. The @scheme[side-length] argument
Constructs a star with five points. The @racket[side-length] argument
determines the side length of the enclosing pentagon.
@mode/color-text
@ -236,12 +236,12 @@ other. The top and bottom pair of angles is @scheme[angle] and the left and righ
image?])]{
Constructs an arbitrary regular star polygon (a generalization of the regular polygons).
The polygon is enclosed by a regular polygon with @scheme[side-count] sides each
@scheme[side-length] long. The polygon is actually constructed by going from vertex to
vertex around the regular polgon, but skipping over every @scheme[step-count] vertices.
The polygon is enclosed by a regular polygon with @racket[side-count] sides each
@racket[side-length] long. The polygon is actually constructed by going from vertex to
vertex around the regular polgon, but skipping over every @racket[step-count] vertices.
For examples, if @scheme[side-count] is @scheme[5] and @scheme[step-count] is @scheme[2],
then this function produces a shape just like @scheme[star].
For examples, if @racket[side-count] is @racket[5] and @racket[step-count] is @racket[2],
then this function produces a shape just like @racket[star].
@mode/color-text
@ -315,9 +315,9 @@ other. The top and bottom pair of angles is @scheme[angle] and the left and righ
[pen-or-color (or/c pen? image-color?)])
image?]{
Adds a line to the image @scheme[image], starting from the point (@scheme[x1],@scheme[y1])
and going to the point (@scheme[x2],@scheme[y2]).
Unlike @scheme[scene+line], if the line passes outside of @scheme[image], the image
Adds a line to the image @racket[image], starting from the point (@racket[x1],@racket[y1])
and going to the point (@racket[x2],@racket[y2]).
Unlike @racket[scene+line], if the line passes outside of @racket[image], the image
gets larger to accomodate the line.
@image-examples[(add-line (ellipse 40 40 "outline" "maroon")
@ -336,19 +336,19 @@ other. The top and bottom pair of angles is @scheme[angle] and the left and righ
[pen-or-color (or/c pen? image-color?)])
image?]{
Adds a curve to @scheme[image], starting at the point
(@scheme[x1],@scheme[y1]), and ending at the point
(@scheme[x2],@scheme[y2]).
Adds a curve to @racket[image], starting at the point
(@racket[x1],@racket[y1]), and ending at the point
(@racket[x2],@racket[y2]).
The @scheme[angle1] and @scheme[angle2] arguments specify the
The @racket[angle1] and @racket[angle2] arguments specify the
angle that the curve has as it leaves the initial point and
as it reaches the final point, respectively.
The @scheme[pull1] and @scheme[pull2] arguments control how
The @racket[pull1] and @racket[pull2] arguments control how
long the curve tries to stay with that angle. Larger numbers
mean that the curve stays with the angle longer.
Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the image
Unlike @racket[scene+curve], if the line passes outside of @racket[image], the image
gets larger to accomodate the curve.
@ -395,12 +395,12 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
Constructs an image that draws the given string, using a complete font specification.
The @scheme[face] and the @scheme[family] combine to give the complete typeface. If
@scheme[face] is available on the system, it is used, but if not then a default typeface
based on the @scheme[family] is chosen. The @scheme[style] controls if the face is italic
or not (under Windows and Mac OS X, @scheme['slant] and @scheme['italic] are the same),
the @scheme[weight] controls if it is boldface (or light), and @scheme[underline?]
determines if the face is underlined. For more details on these arguments, see @scheme[font%],
The @racket[face] and the @racket[family] combine to give the complete typeface. If
@racket[face] is available on the system, it is used, but if not then a default typeface
based on the @racket[family] is chosen. The @racket[style] controls if the face is italic
or not (under Windows and Mac OS X, @racket['slant] and @racket['italic] are the same),
the @racket[weight] controls if it is boldface (or light), and @racket[underline?]
determines if the face is underlined. For more details on these arguments, see @racket[font%],
which ultimately is what this code uses to draw the font.
@image-examples[(text/font "Hello" 24 "olive"
@ -415,7 +415,7 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
([bitmap-spec rel-string
id])]{
Loads the bitmap specified by @scheme[bitmap-spec]. If @scheme[bitmap-spec] is a string, it is treated as a
Loads the bitmap specified by @racket[bitmap-spec]. If @racket[bitmap-spec] is a string, it is treated as a
relative path. If it is an identifier, it is treated like a require spec and used to refer to a file
in a collection.
@ -447,9 +447,9 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
}
@defproc[(overlay/align [x-place x-place?] [y-place y-place?] [i1 image?] [i2 image?] [is image?] ...) image?]{
Overlays all of its image arguments, much like the @scheme[overlay] function, but using
@scheme[x-place] and @scheme[y-place] to determine where the images are lined up. For example, if
@scheme[x-place] and @scheme[y-place] are both @scheme["middle"], then the images are lined up
Overlays all of its image arguments, much like the @racket[overlay] function, but using
@racket[x-place] and @racket[y-place] to determine where the images are lined up. For example, if
@racket[x-place] and @racket[y-place] are both @racket["middle"], then the images are lined up
on their centers.
@image-examples[(overlay/align "left" "middle"
@ -465,8 +465,8 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
}
@defproc[(overlay/xy [i1 image?] [x real?] [y real?] [i2 image?]) image?]{
Constructs an image by overlaying @scheme[i1] on top of @scheme[i2] after
shifting @scheme[i2] over by @scheme[x] pixels to the right and @scheme[y]
Constructs an image by overlaying @racket[i1] on top of @racket[i2] after
shifting @racket[i2] over by @racket[x] pixels to the right and @racket[y]
pixels down.
@image-examples[(overlay/xy (rectangle 20 20 "outline" "black")
20 0
@ -490,7 +490,7 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
@defproc[(underlay [i1 image?] [i2 image?] [is image?] ...) image?]{
Underlays all of its arguments building a single image.
It behaves like @scheme[overlay], but with the arguments in the reverse order.
It behaves like @racket[overlay], but with the arguments in the reverse order.
That is, the first argument goes
underneath of the second argument, which goes underneath the third argument, etc.
The images are all lined up on their centers.
@ -507,9 +507,9 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
}
@defproc[(underlay/align [x-place x-place?] [y-place y-place?] [i1 image?] [i2 image?] [is image?] ...) image?]{
Underlays all of its image arguments, much like the @scheme[underlay] function, but using
@scheme[x-place] and @scheme[y-place] to determine where the images are lined up. For example, if
@scheme[x-place] and @scheme[y-place] are both @scheme["middle"], then the images are lined up
Underlays all of its image arguments, much like the @racket[underlay] function, but using
@racket[x-place] and @racket[y-place] to determine where the images are lined up. For example, if
@racket[x-place] and @racket[y-place] are both @racket["middle"], then the images are lined up
on their centers.
@image-examples[(underlay/align "left" "middle"
@ -525,11 +525,11 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
}
@defproc[(underlay/xy [i1 image?] [x real?] [y real?] [i2 image?]) image?]{
Constructs an image by underlaying @scheme[i1] underneath of @scheme[i2] after
shifting @scheme[i2] over by @scheme[x] pixels to the right and @scheme[y]
Constructs an image by underlaying @racket[i1] underneath of @racket[i2] after
shifting @racket[i2] over by @racket[x] pixels to the right and @racket[y]
pixels down.
This is the same as @scheme[(overlay/xy i2 (- x) (- y) i1)].
This is the same as @racket[(overlay/xy i2 (- x) (- y) i1)].
@image-examples[(underlay/xy (rectangle 20 20 "outline" "black")
20 0
@ -565,8 +565,8 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
@defproc[(beside/align [y-place y-place?] [i1 image?] [i2 image?] [is image?] ...) image?]{
Constructs an image by placing all of the argument images in a horizontal row, lined
up as indicated by the @scheme[y-place] argument. For example, if @scheme[y-place]
is @scheme["middle"], then the images are placed side by side with their centers
up as indicated by the @racket[y-place] argument. For example, if @racket[y-place]
is @racket["middle"], then the images are placed side by side with their centers
lined up with each other.
@image-examples[(beside/align "bottom"
@ -603,8 +603,8 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
@defproc[(above/align [x-place x-place?] [i1 image?] [i2 image?] [is image?] ...) image?]{
Constructs an image by placing all of the argument images in a vertical row, lined
up as indicated by the @scheme[x-place] argument. For example, if @scheme[x-place]
is @scheme["middle"], then the images are placed above each other with their centers
up as indicated by the @racket[x-place] argument. For example, if @racket[x-place]
is @racket["middle"], then the images are placed above each other with their centers
lined up.
@image-examples[(above/align "right"
@ -625,7 +625,7 @@ Unlike @scheme[scene+curve], if the line passes outside of @scheme[image], the i
@section{Placing Images & Scenes}
Placing images into scenes is particularly useful when building worlds
and universes using @scheme[2htdp/universe].
and universes using @racket[2htdp/universe].
@defproc[(empty-scene [width (and/c real? (not/c negative?))]
[height (and/c real? (not/c negative?))])
@ -639,10 +639,10 @@ Creates an empty scene, i.e., a rectangle with a black outline.
@defproc[(place-image [image image?] [x real?] [y real?] [scene image?]) image?]{
Places @scheme[image] onto @scheme[scene] with its center at the coordinates
(@scheme[x],@scheme[y]) and crops the resulting image so that it has the
same size as @scheme[scene]. The coordinates are relative to the top-left
of @scheme[scene].
Places @racket[image] onto @racket[scene] with its center at the coordinates
(@racket[x],@racket[y]) and crops the resulting image so that it has the
same size as @racket[scene]. The coordinates are relative to the top-left
of @racket[scene].
@image-examples[(place-image
(triangle 32 "solid" "red")
@ -671,11 +671,11 @@ Creates an empty scene, i.e., a rectangle with a black outline.
@defproc[(place-image/align [image image?] [x real?] [y real?] [x-place x-place?] [y-place y-place?][scene image?])
image?]{
Like @scheme[place-image], but uses @scheme[image]'s @scheme[x-place] and
@scheme[y-place] to anchor the image. Also, like
@scheme[place-image], @scheme[place-image/align]
Like @racket[place-image], but uses @racket[image]'s @racket[x-place] and
@racket[y-place] to anchor the image. Also, like
@racket[place-image], @racket[place-image/align]
crops the resulting image so that it has the
same size as @scheme[scene].
same size as @racket[scene].
@image-examples[(place-image/align (triangle 48 "solid" "yellowgreen")
64 64 "right" "bottom"
@ -704,9 +704,9 @@ Creates an empty scene, i.e., a rectangle with a black outline.
[color image-color?])
image?]{
Adds a line to the image @scheme[scene], starting from the point (@scheme[x1],@scheme[y1])
and going to the point (@scheme[x2],@scheme[y2]); unlike
@scheme[add-line], this function crops the resulting image to the size of @scheme[scene].
Adds a line to the image @racket[scene], starting from the point (@racket[x1],@racket[y1])
and going to the point (@racket[x2],@racket[y2]); unlike
@racket[add-line], this function crops the resulting image to the size of @racket[scene].
@image-examples[(scene+line (ellipse 40 40 "outline" "maroon")
0 40 40 0 "maroon")
@ -724,20 +724,20 @@ Creates an empty scene, i.e., a rectangle with a black outline.
[color image-color?])
image?]{
Adds a curve to @scheme[scene], starting at the point
(@scheme[x1],@scheme[y1]), and ending at the point
(@scheme[x2],@scheme[y2]).
Adds a curve to @racket[scene], starting at the point
(@racket[x1],@racket[y1]), and ending at the point
(@racket[x2],@racket[y2]).
The @scheme[angle1] and @scheme[angle2] arguments specify the
The @racket[angle1] and @racket[angle2] arguments specify the
angle that the curve has as it leaves the initial point and
as it reaches the final point, respectively.
The @scheme[pull1] and @scheme[pull2] arguments control how
The @racket[pull1] and @racket[pull2] arguments control how
long the curve tries to stay with that angle. Larger numbers
mean that the curve stays with the angle longer.
Unlike @scheme[add-curve], this function crops the curve, only showing
the parts that fit onto @scheme[scene].
Unlike @racket[add-curve], this function crops the curve, only showing
the parts that fit onto @racket[scene].
@image-examples[(scene+curve (rectangle 100 100 "solid" "black")
20 20 0 1/3
@ -767,7 +767,7 @@ the parts that fit onto @scheme[scene].
@section{Rotating, Scaling, Cropping, and Framing Images}
@defproc[(rotate [angle angle?] [image image?]) image?]{
Rotates @scheme[image] by @scheme[angle] degrees in a counter-clockwise direction.
Rotates @racket[image] by @racket[angle] degrees in a counter-clockwise direction.
@image-examples[(rotate 45 (ellipse 60 20 "solid" "olivedrab"))
(rotate 5 (rectangle 50 50 "outline" "black"))
@ -781,15 +781,15 @@ the parts that fit onto @scheme[scene].
@defproc[(scale [factor (and/c real? positive?)] [image image?]) image?]{
Scales @scheme[image] by @scheme[factor].
Scales @racket[image] by @racket[factor].
The pen sizes are also scaled and thus draw thicker (or thinner)
lines than the original image, unless the pen was size
@scheme[0]. That pen size is treated specially to mean ``the
@racket[0]. That pen size is treated specially to mean ``the
smallest available line'' and thus it always draws a one pixel
wide line; this is also the case for @scheme['outline] and @scheme["outline"]
shapes that are drawn with an @scheme[image-color?] instead of
a @scheme[pen].
wide line; this is also the case for @racket['outline] and @racket["outline"]
shapes that are drawn with an @racket[image-color?] instead of
a @racket[pen].
@image-examples[(scale 2 (ellipse 20 30 "solid" "blue"))
@ -800,8 +800,8 @@ the parts that fit onto @scheme[scene].
}
@defproc[(scale/xy [x-factor (and/c real? positive?)] [y-factor (and/c real? positive?)] [image image?]) image?]{
Scales @scheme[image] by @scheme[x-factor] horizontally and by
@scheme[y-factor] vertically.
Scales @racket[image] by @racket[x-factor] horizontally and by
@racket[y-factor] vertically.
@image-examples[(scale/xy 3
2
@ -815,8 +815,8 @@ the parts that fit onto @scheme[scene].
[image image?])
image?]{
Crops @scheme[image] to the rectangle with the upper left at the point (@scheme[x],@scheme[y])
and with @scheme[width] and @scheme[height].
Crops @racket[image] to the rectangle with the upper left at the point (@racket[x],@racket[y])
and with @racket[width] and @racket[height].
@image-examples[(crop 0 0 40 40 (circle 40 "solid" "chocolate"))
(crop 40 60 40 60 (ellipse 80 120 "solid" "dodgerblue"))
@ -829,7 +829,7 @@ the parts that fit onto @scheme[scene].
}
@defproc[(frame [image image?]) image?]{
Returns an image just like @scheme[image], except
Returns an image just like @racket[image], except
with a black, single pixel frame drawn around the
bounding box of the image.
@ -849,7 +849,7 @@ the parts that fit onto @scheme[scene].
@section{Image Properties}
@defproc[(image-width [i image?]) (and/c integer? (not/c negative?) exact?)]{
Returns the width of @scheme[i].
Returns the width of @racket[i].
@image-examples[(image-width (ellipse 30 40 "solid" "orange"))
(image-width (circle 30 "solid" "orange"))
@ -859,7 +859,7 @@ the parts that fit onto @scheme[scene].
}
@defproc[(image-height [i image?]) (and/c integer? (not/c negative?) exact?)]{
Returns the height of @scheme[i].
Returns the height of @racket[i].
@image-examples[(image-height (ellipse 30 40 "solid" "orange"))
(image-height (circle 30 "solid" "orange"))
@ -870,7 +870,7 @@ the parts that fit onto @scheme[scene].
@defproc[(image-baseline [i image?]) (and/c integer? positive? exact?)]{
Returns the distance from the top of the image to its baseline.
Unless the image was constructed with @scheme[text] or @scheme[text/font],
Unless the image was constructed with @racket[text] or @racket[text/font],
this will be the same as its height.
@image-examples[(image-baseline (text "Hello" 24 "black"))
@ -884,60 +884,60 @@ the parts that fit onto @scheme[scene].
This section lists predicates for the basic structures provided by the image library.
@defproc[(image? [x any/c]) boolean?]{
Determines if @scheme[x] is an image. Images are returned by functions
like @scheme[ellipse] and @scheme[rectangle] and
accepted by functions like @scheme[overlay] and @scheme[beside].
Determines if @racket[x] is an image. Images are returned by functions
like @racket[ellipse] and @racket[rectangle] and
accepted by functions like @racket[overlay] and @racket[beside].
Additionally, images inserted into a DrRacket window are treated as
bitmap images, as are instances of @scheme[image-snip%] and @scheme[bitmap%].
bitmap images, as are instances of @racket[image-snip%] and @racket[bitmap%].
}
@defproc[(mode? [x any/c]) boolean?]{
Determines if @scheme[x] is a mode suitable for
Determines if @racket[x] is a mode suitable for
constructing images. It can be one of
@scheme['solid], @scheme["solid"], @scheme['outline],
or @scheme["outline"], indicating if the shape is
@racket['solid], @racket["solid"], @racket['outline],
or @racket["outline"], indicating if the shape is
filled in or not.
}
@defproc[(image-color? [x any/c]) boolean?]{
Determines if @scheme[x] represents a color. Strings, symbols,
and @scheme[color] structs are allowed as colors.
Determines if @racket[x] represents a color. Strings, symbols,
and @racket[color] structs are allowed as colors.
For example,
@scheme["magenta"], @scheme["black"], @scheme['orange], and @scheme['purple]
@racket["magenta"], @racket["black"], @racket['orange], and @racket['purple]
are allowed. Colors are not case-sensitive, so
@scheme["Magenta"], @scheme["Black"], @scheme['Orange], and @scheme['Purple]
@racket["Magenta"], @racket["Black"], @racket['Orange], and @racket['Purple]
are also allowed, and are the same colors as in the previous sentence.
If a string or symbol color name is not recognized, black is used in its place.
The complete list of colors is available in the documentation for
@scheme[color-database<%>].
@racket[color-database<%>].
}
@defstruct[color ([red (and/c natural-number/c (<=/c 255))]
[green (and/c natural-number/c (<=/c 255))]
[blue (and/c natural-number/c (<=/c 255))])]{
The @scheme[color] struct defines a color with red, green, and blue components
that range from @scheme[0] to @scheme[255].
The @racket[color] struct defines a color with red, green, and blue components
that range from @racket[0] to @racket[255].
}
@defproc[(y-place? [x any/c]) boolean?]{
Determines if @scheme[x] is a placement option
Determines if @racket[x] is a placement option
for the vertical direction. It can be one
of
@scheme["top"],
@scheme['top],
@scheme["bottom"],
@scheme['bottom],
@scheme["middle"],
@scheme['middle],
@scheme["center"],
@scheme['center],
@scheme["baseline"], or
@scheme['baseline].
@racket["top"],
@racket['top],
@racket["bottom"],
@racket['bottom],
@racket["middle"],
@racket['middle],
@racket["center"],
@racket['center],
@racket["baseline"], or
@racket['baseline].
The baseline of an image is the place where the bottoms any letters line up, not counting descenders, e.g. the tail on ``y'' or ``g'' or ``j''.
@ -945,27 +945,27 @@ The baseline of an image is the place where the bottoms any letters line up, not
}
@defproc[(x-place? [x any/c]) boolean?]{
Determines if @scheme[x] is a placement option
Determines if @racket[x] is a placement option
for the horizontal direction. It can be one
of @scheme["left"],
@scheme['left],
@scheme["right"],
@scheme['right],
@scheme["middle"],
@scheme['middle],
@scheme["center"], or
@scheme['center].
of @racket["left"],
@racket['left],
@racket["right"],
@racket['right],
@racket["middle"],
@racket['middle],
@racket["center"], or
@racket['center].
}
@defproc[(angle? [x any/c]) boolean?]{
Determines if @scheme[x] is an angle, namely
a real number between @scheme[0] (inclusive)
and @scheme[360] (exclusive).
Determines if @racket[x] is an angle, namely
a real number between @racket[0] (inclusive)
and @racket[360] (exclusive).
}
@defproc[(side-count? [x any/c]) boolean?]{
Determines if @scheme[x] is an integer
greater than or equal to @scheme[3].
Determines if @racket[x] is an integer
greater than or equal to @racket[3].
}
@defproc[(step-count? [x any/c]) boolean?]{
@ -977,42 +977,42 @@ The baseline of an image is the place where the bottoms any letters line up, not
[style pen-style?]
[cap pen-cap?]
[join pen-join?])]{
The @scheme[pen] struct specifies how the drawing library draws lines.
The @racket[pen] struct specifies how the drawing library draws lines.
A good default for @scheme[style] is @scheme["solid"], and
good default values for the @scheme[cap] and @scheme[join] fields
are @scheme["round"].
A good default for @racket[style] is @racket["solid"], and
good default values for the @racket[cap] and @racket[join] fields
are @racket["round"].
Using @scheme[0] as a width is special; it means to always draw the
Using @racket[0] as a width is special; it means to always draw the
smallest possible, but visible, pen. This means that the pen will always
be one pixel in size, no matter how the image is scaled.
}
@defproc[(pen-style? [x any/c]) boolean?]{
Determines if @scheme[x] is a valid pen style.
Determines if @racket[x] is a valid pen style.
It can be one of
@scheme["solid"], @scheme['solid],
@scheme["dot"], @scheme['dot],
@scheme["long-dash"], @scheme['long-dash],
@scheme["short-dash"], @scheme['short-dash],
@scheme["dot-dash"], or @scheme['dot-dash].
@racket["solid"], @racket['solid],
@racket["dot"], @racket['dot],
@racket["long-dash"], @racket['long-dash],
@racket["short-dash"], @racket['short-dash],
@racket["dot-dash"], or @racket['dot-dash].
}
@defproc[(pen-cap? [x any/c]) boolean?]{
Determines if @scheme[x] is a valid pen cap.
Determines if @racket[x] is a valid pen cap.
It can be one of
@scheme["round"], @scheme['round],
@scheme["projecting"], @scheme['projecting],
@scheme["butt"], or @scheme['butt].
@racket["round"], @racket['round],
@racket["projecting"], @racket['projecting],
@racket["butt"], or @racket['butt].
}
@defproc[(pen-join? [x any/c]) boolean?]{
Determines if @scheme[x] is a valid pen join.
Determines if @racket[x] is a valid pen join.
It can be one of
@scheme["round"], @scheme['round],
@scheme["bevel"], @scheme['bevel],
@scheme["miter"], or @scheme['miter].
@racket["round"], @racket['round],
@racket["bevel"], @racket['bevel],
@racket["miter"], or @racket['miter].
}
@section{Equality Testing of Images}
@ -1025,18 +1025,18 @@ Two images are equal if they draw exactly the same way, at their current size
The image library treats coordinates as if they are in the upper-left corner
of each pixel, and infinitesimally small.
Thus, when drawing a solid @scheme[square] of whose side-length is 10, the image library
colors in all of the pixels enclosed by the @scheme[square] starting at the upper
Thus, when drawing a solid @racket[square] of whose side-length is 10, the image library
colors in all of the pixels enclosed by the @racket[square] starting at the upper
left corner of (0,0) and going down to the upper left corner of (10,10),
so the pixel whose upper left at (9,9) is colored in, but the pixel
at (10,10) is not. All told, 100 pixels get colored in, just as expected for
a @scheme[square] with a side length of 10.
a @racket[square] with a side length of 10.
When drawing lines, however, things get a bit more complex. Specifically,
imagine drawing the outline of that rectangle. Since the border is
between the pixels, there really isn't a natural pixel to draw to indicate
the border. Accordingly, when drawing an outline @scheme[square] (without a
@scheme[pen] specification, but just a color as the last argument),
the border. Accordingly, when drawing an outline @racket[square] (without a
@racket[pen] specification, but just a color as the last argument),
the image library uses a pen whose width is 1 pixel, but draws a line
centered at the point (0.5,0.5) that goes down and around to the point (10.5,10.5).
This means that the outline slightly exceeds the bounding box of the shape.
@ -1044,12 +1044,12 @@ 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 special case of adding 0.5 to each coordinate when drawing the square
applies to all polygon-based shapes, but does not apply when a @scheme[pen]
applies to all polygon-based shapes, but does not apply when a @racket[pen]
is passed as the last argument to create the shape.
In that case, not adjustment of the pixels is performed and using a one
pixel wide pen draws the pixels above and below the line, but each with
a color that is half of the intensity of the given color. Using a
@scheme[pen] with with two, colors the pixels above and below the line
@racket[pen] with with two, colors the pixels above and below the line
with the full intensity.
@ -1058,14 +1058,14 @@ with the full intensity.
In order to use an image as an input to another program (Photoshop, e.g., or
a web browser), it is necessary to represent it in a format that these programs
can understand. The @scheme[save-image] function provides this functionality,
can understand. The @racket[save-image] function provides this functionality,
writing an image to disk using the @tt{PNG} format. Since this
format represents an image using a set of pixel values, an image written to disk
generally contains less information than the image that was written, and cannot be scaled
or manipulated as cleanly (by any image program).
@defproc[(save-image [image image?] [filename path-string?]) boolean?]{
writes an image to the path specified by @scheme[filename], using the
writes an image to the path specified by @racket[filename], using the
@tt{PNG} format.}