(square-limit wave 3)


(square-limit rogers 5)

This is an implementation of the picture language described in section 2.2.4 of Structure and Interpretation of Computer Programs, using the GIMP's Script-Fu facility. It includes code taken directly from the book, procedures that were left as exercises, a procedure (file->painter) for turning an arbitrary image file into a painter and a procedure (paint) that makes it easy to render a painter into an image. All output is displayed using the GIMP's user interface.

To install it, put the file painter.scm in your GIMP scripts directory (~/.gimp-2.0/scripts). To try it out, start up the GIMP and open the Script-Fu console (Xtns->Script-Fu->Script-Fu Console). Try doing

(paint wave default-frame)

default-frame is a square frame 256 pixels wide by 256 tall. In addition to wave, you get the painters outline-painter, x-painter and diamond-painter. Try something like

(paint (below (beside (flip-horiz (right-split x-painter 2))
                      (right-split wave 2))
              (beside (flip-horiz (right-split diamond-painter 2))
                      (right-split outline-painter 2)))

to see what they look like.

The paint procedure creates an image that is big enough to contain each vertex of the given frame and also the coordinate (0, 0), and paints the given painter inside the frame. Segment-based painters are drawn with the current paintbrush.

You can create a painter from an image file:

(define rogers (file->painter "rogers.png"))

These painters can be used like any other.

The parts of painter.scm that are my own work are in the public domain.

Download painter.scm.