☰ Contents Appendix: The Pict Library

Pict Library Reference

Shapes

A size of 0 makes an empty picture, such as new Rect(0, 0, "white"): it takes up no room, so it is a handy starting point for building a picture up piece by piece. A negative size is an error.

Colors

"red", "green", "blue", "yellow", "orange", "pink", "magenta", "cyan", "purple", "brown", "black", "white", "gray", "grey", "lightgray", "darkgray"

"transparent" paints nothing, but takes up its size like any other picture.

Combinations

Transformations

Pict Methods

Fractional Sizes and Angles

Every size, position, thickness, and angle above also accepts a double, rounded to the nearest whole pixel or degree. A picture stores and prints whole numbers either way. A measurement of NaN or infinity is an error.

Rasters

A Raster is a rectangle of pixels, each a Color from java.awt (start the file with import java.awt.Color;). x counts across from the left and y counts down from the top, both starting at 0.

Two rasters are equals when they have the same size and the same color at every pixel, however they were made. Pict.render() turns any picture into a raster.

Java Colors

A Color prints as java.awt.Color[r=…,g=…,b=…], without its alpha, so a transparent pixel prints the same as black.

Showing and Saving

Showing an empty picture puts up a small gray dotted circle, so you can see that something was shown. Saving one is an error, because PNG and GIF files need at least one pixel.

The book’s images: images/geisel.png, images/salk.png, images/cove.png, images/blacks-beach.png, images/torrey-cliffs.png, images/pier.png, images/pier-under.png

Credits

The Pict library is based on the image library from How to Design Programs and Racket, and on work by Ben Lerner at Northeastern University. It is re-implemented here to make it run well in the book and suit the needs of this course.