From 86d08f4197946b58115870043fc99727a0eb10d7 Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Tue, 18 Jul 2006 14:10:47 +0000 Subject: [PATCH] image docs fixed svn: r3749 --- collects/teachpack/htdp/Docs/image.thtml | 204 +++++++++++++---------- 1 file changed, 116 insertions(+), 88 deletions(-) diff --git a/collects/teachpack/htdp/Docs/image.thtml b/collects/teachpack/htdp/Docs/image.thtml index 5d00161a81..ef141a23cf 100644 --- a/collects/teachpack/htdp/Docs/image.thtml +++ b/collects/teachpack/htdp/Docs/image.thtml @@ -1,98 +1,160 @@ { (define LIBNAME "Images") (include "head.tinc") } -This teachpack provides primitives for constructing and -manipulating images. +This teachpack provides primitives for constructing and manipulating +images. Basic images are created as outlines or solid shapes. Additional +primitives allow for the composition of images. -These functions create basic shapes. The mode can be either -'solid or "solid", meaning the -shape is filled in, or 'outline or -"outline", meaning the shape is hollow. Image -colors can be either symbols (like 'blue), -strings (like "blue"), or color structs (like -(make-color 0 0 255)) -- see below for more -information about color structs. +Data definition: +
+
+;; Mode is one of the following two symbols or strings: 
+;; -- 'solid 
+;; -- 'outline 
+;; -- "solid"
+;; -- "outline"
+
+
+Interpretation: 'solid is used for creating solid basic +shapes; 'outline is used for creating outlines of basic +shapes. Strings are used in an analogous manner. +Data definition: +
+
+;; Color is one of:
+;; -- a color symbol, e.g., 'blue
+;; -- a color string, e.g., "blue"
+;; -- a color struct, e.g., (make-color 0 0 255), which also denotes blue. 
+
+
+Interpretation: Color arguments are used to paint the shapes +or their outlines. See below for more information about color structs. + +The following predicate precisely specifies what a valid image color is: -
  • {(idx rectangle)} : int int mode image-color -> image
    +
  • {(idx image-color?)} : anything -> boolean
    + to determine if the input is a valid image color +
  • + +The following functions create basic shapes (Image): + +
  • {(idx rectangle)} : Int Int Mode Color -> Image
    to create a rectangle using the given width, height, mode, and color -
  • {(idx circle)} : int mode image-color -> image
    + +
  • {(idx circle)} : Int Mode Color -> Image
    to create a circle using the given radius, mode, and color -
  • {(idx ellipse)} : int int mode image-color -> image
    + +
  • {(idx ellipse)} : Int Int Mode Color -> Image
    to create an ellipse using the given width, height, and color -
  • {(idx triangle)} : int mode iamge-color -> image
    + +
  • {(idx triangle)} : Int Mode Color -> Image
    to create an upward pointing equilateral triangle using the given edge size and color -
  • {(idx line)} : number number image-color -> image
    - to create an image with a colored line from (0,0) to the - point with the given coordinates -
  • {(idx add-line)} : image number number number number image-color -> image
    + +
  • {(idx line)} : Int Int Color -> Image
    to create an + image with a colored line from (0,0) to the point with the given + coordinates + +
  • {(idx add-line)} : Image Int Int Int Int Color -> Image
    to add a line to an existing image, drawn between the two given points -
  • {(idx text)} : string size image-color -> image
    - to create an image of the text in the given string, with the point size, and color specified by the last two arguments + +
  • {(idx text)} : String Size Color -> Image
    + to create an image of the text in the given string, with the point size, + and color specified by the last two arguments
  • -These functions build complex images from the basic -shapes. When two images are laid on top of each other, the -are lined up at their pinhole. Most shapes have their -pinholes in the middle. The exceptions are -text and line which have their -pinholes in the top-left corner. +Images have many properties. To understand how functions manipulate and +create images, we need to understand one of these properties immediately: +pinholes. Each image, including primitive shapes, come with a +pinhole. Usually the pinhole is in the center of the shape except for those +created from line and text, which have pinholes +at the top left. When in doubt you can always find out where the pinhole is +and even place it somewhere else: -
  • {(idx overlay)} : image image image ... -> image
    - to add the pixels of the second image onto the first image, lining up the pinholes -
  • {(idx overlay/xy)} : image int int image -> image
    - to add the pixels of the second image onto the first image. Instead of lining up - on the pinhole, the second image's pinhole is lined up with an offset from the - first image's pinhole. The two coordinates specify how far down and to the right - the offset should be. - The pinhole of the resulting image is the same place as the pinhole - in the first image. +
  • {(idx pinhole-x)} : Image -> Int
    + to determine the x coordinate of the pinhole, measuring from + the left of the image + +
  • {(idx pinhole-y)} : Image -> Int
    + to determine the y coordinate of the pinhole, measuring down from + the left of the image + +
  • {(idx put-pinhole)} : Image Int Int -> Image
    + to put the pinhole in the location specified by the arguments, counting + from the left and down from the top, respectively. + +
  • {(idx move-pinhole)} : Image Int Int -> Image
    + to move the pinhole down and to the right (by the specified amounts) of + its current location. Use negative numbers to move it up or to the left.
  • -After an image has been overlaid on another, it is possible -to recover the position of overlaid image, using the next -two functions. - +The next group of functions build images from images: -
  • {(idx image-inside?)} : image image -> boolean
    - to determine whether the pixels of the second image appear in the first +
  • {(idx overlay)} : Image Image Image ... -> Image
    + to add the pixels of the second Image onto the first image. The operation + lines up the images via their pinholes. -

    Be careful when using this function with jpeg images. If -you use an image-editing program to crop a jpeg image and -then save it, image-inside? will not recognize -the cropped image, due to jpeg's compression.

    +
  • {(idx overlay/xy)} : Image Int Int Image -> Image
    to + add the pixels of the second image onto the first image. Instead of lining + up on the pinhole, the second image's pinhole is lined up with an offset + from the first image's pinhole. The two coordinates specify how far down + and to the right the offset should be. The pinhole of the resulting image + is the same place as the pinhole in the first image. +
  • -

    Use png images instead.

    +For composite images, it is always possible to determine whether one occurs +in the other and where: + +
  • {(idx image-inside?)} : Image Image -> Boolean
    + to determine whether the pixels of the second image appear in the first. -
  • {(idx find-image)} : image image -> posn
    +

    Be careful when using this function with jpeg images. If you use an +image-editing program to crop a jpeg image and then save it, +image-inside? will not recognize the cropped image, due to +standard compression applied to JPEG images.

    + +

    Use PNG images instead whenever possible.

    + +
  • {(idx find-image)} : Image Image -> Posn
    to determine where the pixels of the second image appear in the first, with respect to the pinhole of the first image.
  • +Two more properties of images are useful for image manipulations: their +width and height. The two functions for extracting these properties are: + +
  • {(idx image-width)} : Image -> Int
    + to obtain an Image's width in pixels +
  • {(idx image-height)} : Image -> Int
    + to obtain an image's height in pixels +
  • + The shrink functions trim an image by eliminating extraneous pixels. -
  • {(idx shrink-tl)} : image number number -> image
    +
  • {(idx shrink-tl)} : Image Int Int -> Image
    to shrink the image, starting from the top-left corner. The two numbers indicate how many pixels to save. The pinhole of the resulting image is in the middle of the image.
  • -
  • {(idx shrink-tr)} : image number number -> image
    + +
  • {(idx shrink-tr)} : Image Int Int -> Image
    to shrink the image, starting from the top-right corner. The two numbers indicate how many pixels to save. The pinhole of the resulting image is in the middle of the image.
  • -
  • {(idx shrink-bl)} : image number number -> image
    + +
  • {(idx shrink-bl)} : Image Int Int -> Image
    to shrink the image, starting from the bottom-left corner. The two numbers indicate how many pixels to save. The pinhole of the resulting image is in the middle of the image.
  • -
  • {(idx shrink-br)} : image number number -> image
    +
  • {(idx shrink-br)} : Image Int Int -> Image
    to shrink the image, starting from the bottom-right corner. The two numbers indicate how many pixels to save. The pinhole of the resulting image is in the middle of the image.
  • -
  • {(idx shrink)} : image number number number number -> image
    +
  • {(idx shrink)} : Image Int Int Int Int -> Image
    to shrink an image around its pinhole. The numbers are the pixels to save to left, above, to the right, and below the pinhole, respectively. The pixel directly on the pinhole is @@ -100,43 +162,9 @@ always saved.
  • -These functions provide information about the image's size. - - -
  • {(idx image-width)} : image -> number
    - to obtain an image's width in pixels -
  • {(idx image-height)} : image -> number
    - to obtain an image's height in pixels -
  • - -This functions provide information and manipulate an image's -pinhole. - - -
  • {(idx pinhole-x)} : image -> number
    - to determine the x coordinate of the pinhole, measuring from - the left of the image -
  • {(idx pinhole-y)} : image -> number
    - to determine the y coordinate of the pinhole, measuring down from - the left of the image -
  • {(idx move-pinhole)} : image number number -> image
    - to move the pinhole down and to the right (by the specified amounts) of - its current location. Use negative numbers to move it up or to the left. -
  • {(idx put-pinhole)} : image number number -> image
    - to put the pinhole in the location specified by the arguments, counting - from the left and down from the top, respectively. -
  • - -This function precisely specifies what a valid image color is. - - -
  • {(idx image-color?)} : anything -> boolean
    - to determine if the input is a valid image color -
  • - -The next functions separate an image into its consitiuent -colors and combine pixels together to build an image. +The next functions separate an image into its consitiuent colors and +combine pixels together to build an image.
  • {(idx image->color-list)} : image -> list-of-color
    to convert an image to a list of colors