Using the Functional Graphics Library with Gambit
unix-fungraph.scm 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
This version of the library only works on unix-like systems (such as
Linux), hence the other part of the name.
This library displays an image by writing it out as an Encapsulated
PostScript (EPS) file and then invoking a seperate program
to display the file. Normally this is unobtrusive, since the
displaying is automatically done whenever the read-eval-print loop
encounters a value that is an image, and because the file is deleted
after it has been displayed. However, you need to be aware of
what is going on behind the scenes in order to tailor the library to
the requirements of particular installations, and in order to help
troubleshoot any problems that arise. Each time a value resulting
from a top-level evaluation is an image, the following steps occur:
- A filename is created of the form imageN.eps, where N is replaced
by the number of of the image (first 1, then 2, etc.). The file is in
the current directory.
- The image is written out to that file in EPS format, using the
save-image-as-epsf procedure described later.
- The ghostview
program, a publically available PostScript previewer, is invoked to
display the file. Gambit continues without waiting for ghostview, but
arranges that when the user has quit out of ghostview, the rm
program is used to delete the file. It is easy to change the commands
used in the library, for example to specify a different previewer.
- Gambit displays something like #[image 1 100x100] as a textual
version of the value. The number 1 in this example corresponds to the
filename image1.eps, and can be used to tell which ghostview window
is displaying which image, if you have several up. The 100x100 in the
example is the size of the image.
In addition to the procedures described in the textbook, there are three
- This procedure writes the image out to an Encapsulated PostScript
file with the given filename.
- This is an advanced feature that allows you to make an image with
any arbitrary string of PostScript code used to
specify the contents.
- 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. The unit of measure is the
point, i.e., 1/72 of an inch.
- This is a shorthand, equivalent to
i.e., the specified size is used as both the width and the height
of the new image.
- This is a further shorthand, equivalent to
i.e., the width and height are both taken as the value of
default-image-size. As described below, this is the same
name that controls the size of the images created by
The images produced by
ps-image are of a size determined by the value of
default-image-size. Initially this name is
defined as 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 redefine it to another value (which
must be an exact, positive integer) to suit your own needs. Or, you
can use the
resize-image procedure described above. For
example, when defining the basic blocks for quilting, it may make
sense to do so as in the following example:
(filled-triangle 0 1 0 -1 1 -1)
Or, as a final option, you can specify a size as an additional
argument to the basic image construction procedures, as in the
(filled-triangle 0 1 0 -1 1 -1 25))
You can specify a size in this way with
ps-image as well as
filled-triangle, and can
also specify two values, for width and height, as with
stack procedures are not
restricted to two arguments, but rather can take one or more.
For more information, see the parent web page, or contact Max Hailperin:
Mathematics and Computer Science Department
Gustavus Adolphus College
800 W. College Avenue
St. Peter, MN 56082