CS151 Labs

Lab 3 will be collected from your subversion repository on Monday, October 17, at 5pm.

Please update your subversion repository with

svn up
Work in the file lab3/lab3.rkt. It is important that this file has exactly this name and location; we will be looking for your work under this name at collection time.

This week, you will practice writing recursive functions to produce a series of increasingly complex images. As you will see, it's amazing how much complexity can arise from the repeated application of just a few simple rules.

A Classic

Today's exercise builds towards reproducing a figure from Abelson and Sussman's text Structure and Interpretation of Computer Programs ("SICP").

This is not the actual figure from that text, but its construction is fundamentally the same.

To test all your functions today, use the following image as your building block. It is included in the lab3.rkt. You can produce it by evaluating (design 64).

Proceed by writing the functions specified below. In doing so you will build the skills -- and a toolkit -- to reproduce the figure above. For this exercise, use anything useful from 2htdp/image. In particular, you will likely want to use scale, beside, and above.

Note that these functions are exercises, and not strictly cumulative. That is, you won't necessarily need to call functions you've already written in later functions.


;; quarter : img -> img

The function quarter should consume a square image and produce one whose side length is half as long. (The image produced has one quarter the area of the image consumed.)

;; row : num img -> img

The function row should produce a row of n images. For example, (row 4 (design 64)) should produce this:

;; col : num img -> img

The function col should produce a column of n images. For example, (col 3 (design 64)) should produce this:

;; grid : num num img -> img

The function grid should produce a grid of images of the given dimensions. The first argument is the grid width, the second is the height. For example, (grid 7 2 (design 64)) should produce this:

;; shrinking-row : img -> img

The function shrinking-row should produce a row of images with the following property: the original square image (the one given as an argument) should be scaled down to 3/4 its original size, with respect to side length (not area), at every step. For example, (shrinking-row (design 64)) should produce this:

;; bsr : img -> img

bsr stands for "bidirectional shrinking row" (for lack of a better name). It's better explained as a picture than in words. (bsr (design 64)) should produce this:

Again, the image's sides are scaled 3/4 at every step.

;; sicp : img -> img

(sicp (design 64)) should produce this:

The pattern is full of self-similarities and mirrorings. Exploit them by writing auxiliary functions to assist in its construction.

There are suggestions for some enhancements at the bottom of the starter file. Have a look! (No extra credit.)

Good luck, everyone. As usual, you will be evaluated not only on the correctness of your final results, but also on proper documentation, including contracts and purposes for all functions, style (judicious code factoring and no spaghetti code), and ample tests.

Commit to submit! Don't neglect to commit your finished work by the deadline.