Using the Functional Graphics Library with DrScheme

The fungraph.ss library provides the procedures for producing graphical images described in Concrete Abstractions. Because these procedures operate like mathematical functions, we refer to them as functional graphics, hence the name fungraph.

Bug note:Unless you are using a Mac or Windows machine, read about a bug.

As of May 2007 (coinciding with the release of DrScheme version 370), this library has been redesigned to use DrScheme's built-in notion of what an "image" is. The most significant consequence of this is that DrScheme's "Insert Image..." command (in the "Special" menu) can be used to insert an image from a standard graphics file (such as a photograph), which can then be manipulated using the procedures in the functional graphics library.

In addition to the procedures described in the textbook, there are five additional ones:

(write-image-as-epsf image filename)
This procedure writes the image out to an Encapsulated PostScript file with the given filename.
(mirror-image image)
Like quarter-turn-right or invert, this takes an image and makes another, related image. In the case of mirror-image, the new image is the same size as the original, and is formed by flipping the original image around a vertical axis, as though it were viewed in a mirror.
(resize-image image width height)
This makes a new image similar to the original, but stretched or shrunk as necessary to have the specified width and height. This may also imply a change in the image's proportions. The width and height must both be exact, positive integers. Now that the functional graphics library uses DrScheme's own (bitmapped) images, the resizing can produce ugly, jagged results. As such, this procedure is best avoided when possible.
(resize-image image size)
This is a shorthand, equivalent to (resize-image image size size), i.e., the specified size is used as both the width and the height of the new image.
(resize-image image)
This is a further shorthand, equivalent to (resize-image image default-image-size default-image-size), i.e., the width and height are both default-image-size, which is a parameter that can be inspected or altered using the next two procedures. As described below, this is the same parameter that controls the size of the images created by line and filled-triangle.
(get-default-image-size)
This returns the current value of default-image-size.
(set-default-image-size! new-value)
This changes the value of default-image-size to new-value.
(threshold image level)
This converts a color or grayscale image into a black-and-white one. For each pixel, if the sum of the red, green, and blue intensities (each on a scale of 0 to 255) exceeds the specified level, then the pixel is mapped into white, otherwise into black.

The images produced by line and filled-triangle are of a size determined by the default-image-size. Initially this is 100. This is a compromise size, a bit small for the fractals in chapter 4 and rather large for each basic block of the quilts in chapters 1-3. You can set it to another value (which must be an exact, positive integer) to suit your own needs. For example, when defining the basic blocks for quilting, it may make sense to first set the default image size to 50.

The images produced by the procedures in this library show up in the interaction window, the same way any other value would. They can be copied and pasted within DrScheme. In particular, you can copy them into the argument position of a call to one of the image-transforming procedures, just as you might copy a numeric value into the argument position of an arithmetic procedure. You can do the same with images inserted into DrScheme using the Special menu's Insert Image... option.

The first argument to the overlay procedure should be a black-and-white image (such as is produced by the line, filled-triangle, and threshold procedures). The white areas are treated as transparent, allowing the second image to show through. (The second image may be any kind of image, including a color or grayscale one.) If the first image is a color or grayscale image, even its white areas are treated as opaque, completely obscuring the second image.


For more information, see the parent web page, or contact Max Hailperin:
Email: max@gustavus.edu
Mathematics and Computer Science Department
Gustavus Adolphus College
800 W. College Avenue
St. Peter, MN 56082
USA
Revision 1.1 as of 2008/06/24 17:55:19