Teachpacks for How to Design Programs

Composing Images


image.ss

This teachpack provides primitives for constructing and manipulating images. These functions create basic shapes. The mode can be either 'solid, meaning the shape is filled in, or 'outline, meaning the shape is hollow. Colors can be either strings, symbols, or color structs (see below).
  • rectangle : int int mode image-color -> image
    to create an image of a rectangle using the given width, height, mode, and color
  • circle : int mode image-color -> image
    to create an image of a circle using the given radius, mode, and color
  • ellipse : int int mode image-color -> image
    to create an image of an ellipse using the given width, height, and color
  • triangle : int mode iamge-color -> image
    to create an equilateral triangle using the given edge size and color
  • line : int int image-color -> image
    to create an image with a colored line from (0,0) to the point with the given coordinates
  • add-line : image int int int int image-color -> image
    to add a line to an existing image, drawn between the two given points
  • text : string size image-color -> image
    to create an image from the given string, point size, and background color
  • These functions build more 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 right in the middle. The exceptions are text and line which have their pinholes in the top-left corner.
  • overlay : image image image ... -> image
    to add the pixels of the second image onto the first image, lining up the pinholes
  • overlay/xy : image int int image -> image
    to add the pixels of the second image onto the first image, lining up down and to the right of the first image's pinhole
  • After an image has been built up using overlays, it is possible to recover the position of the pieces of the image, using the next two functions.
  • image-inside : image image -> boolean
    to determine whether the pixels of the second image appear in the first
  • find-image : image image -> posn
    to determine where the pixels of the second image appear in the first
  • The rest of this teachpack are supplementary functions for manipulating images and colors.
  • image-color? : anything -> boolean
    to determine if the input names a valid color.
  • image-width : image -> number
    to obtain an image's width in pixels
  • image-height : image -> number
    to obtain an image's height in pixels
  • image->color-list : image -> list-of-color
    to convert an image to a list of colors
  • color-list->image : list-of-color int int -> image
    to convert a list of colors to an image with the given width and height
  • make-color : int int int -> color
    to construct a color
  • color? : anything -> boolean
    to determine if its input is a color
  • color-red : color -> int
    to extract the red component of a color
  • color-green : color -> int
    to extract the green component of a color
  • color-blue : color -> int
    to extract the blue component of a color
  • image->alpha-color-list : image -> list-of-alpha-color
    to convert an image to a list of alpha colors
  • alpha-color-list->image : list-of-alpha-color int int -> image
    to convert a list of alpha colors to an image with the given width and height"
  • make-alpha-color : int int int int -> color
    to construct an alpha color
  • alpha-color? : anything -> boolean
    to determine if its input is a color
  • alpha-color-alpha : color -> int
    to extract the alpha value of a color
  • alpha-color-red : color -> int
    to extract the red component of a color
  • alpha-color-green : color -> int
    to extract the green component of a color
  • alpha-color-blue : color -> int
    to extract the blue component of a color"