Assigned: Thursday, October 6
Due: Thursday, October 13 by 10:30pm
Please read the exam procedures page for policies, turn-in procedures, and grading details. If you have any questions about the exam, check the Q&A at the bottom of this page. We will generally spend some time in class every day on questions and answers while the exam is in progress.
While the exam is out, please check back periodically to see if we have reported any new errata.
Complete the exam using the exam2.rkt starter source code. Please rename this file to 000000.rkt, but replace 000000 with your assigned random number.
Topics: drawings as values, booleans as predicates
A rectangle can be specified by giving the coordinates of the left, top, right, and bottom edges of the rectangle. It is often useful to check whether a drawing is contained within a particular rectangular area of the coordinate system. We often call a rectangular area that contains a drawing a “bounding box” for that drawing.
Write a procedure (in-bounds? drawing left top right bottom) that checks if a drawing is contained by the rectangular area defined by the coordinates of left, top, right, and bottom. A few example executions of the procedure are shown below.
> (in-bounds? drawing-unit-circle -1 -1 1 1)
#t
In this example, the rectangular area is centered at the origin with a height of 2 and a width of 2. Since the unit circle is also centered at the origin and has diameter 1, the circle is completely contained by the bounding box.
> (in-bounds? drawing-unit-circle -1 0 1 1)
#f
The box above has a left edge at -1, a top edge of 0, a right edge of 1, and a bottom edge of 1. Therefore the box contains the lower half of the unit circle, but since the circle extends up to -0.5, the box does not contain it.
Topics: testing
Write a test suite for the (in-bounds? drawing left top right bottom) procedure from the previous problem. Your test suite must contain at least 8 separate tests that provide a good coverage of the possible cases.
Topics: GIMP tools, map, local bindings
Write and document a procedure, (semicircles-a width height n radius), that produces an image using GIMP tools with dimensions width by height that contains n semicircles with radius radius spaced evenly across the width of the image. The n semicircles should be cycle through the colors red, green, and blue. If semicircles overlap, the ones to the right should appear in front of semicircles to the left.
When you write postconditions for image-building procedures, you will need to be somewhat informal. You should describe the image in some detail, including the locations and sizes of shapes in the result, and how those shapes overlap.
The following examples should help you test your implementation:
(image-show (semicircles-a 200 100 3 50))

(image-show (semicircles-a 200 100 8 50))

(image-show (semicircles-a 300 100 50 50))

image-compute editionTopics: image-compute, conditionals, local bindings, anonymous procedures
Write and document a procedure, (semicircles-b width height radius), that returns an image with dimensions width by height that contains three semicircles with radius radius spaced evenly across the width of the image. The three circles should be colored with red to white, green to white, and blue to white radial blends, respectively. A radial blend is one where the color changes based on the distance from the center of a shape, rather than from edge to edge. If the semicircles include overlapping areas, the green semicircle should appear in front of the blue semicircle, and the red semicircle should appear in front of the green semicircle.
Your procedure should create an image but not show it. It’s easy to call your procedure and show the resulting image if that’s what we want, but if your procedure automatically shows the image then we have no way to disable the image-show. This is a general style guideline that applies to many side effects: if your procedure does not need a side effect to work (such as a call to image-show, display, or read) then you should omit it and let the user of the procedure handle inputs and outputs as they see fit.
Here are a few example calls to semicircles-b:
(image-show (semicircles-b 150 150 50))

(image-show (semicircles-b 150 150 75))

(image-show (semicircles-b 300 150 75))

Topics: documentation, code reading, numeric values
Sometimes students (and professors) come up with difficult-to-read solutions to simple problems, like this one below:
(define pair ( lambda ( scale)
(let* ( [p symbol?] [q list?]
[ r 'other ] [s 'symbol ] [t
'pair] [ u number?][v pair?
] [w 'list] [x 'string] [y
'number ] [z string?] [
image ( lambda ( drawing
)(cond [( u drawing ) y
] [ (and ( not (u
drawing) )( p drawing
) ) s] [ (q drawing)
w] [(or (q drawing)
( v drawing)) t][(
z drawing ) x][
else r] ))])(map
image scale))))
a. Clean up this procedure. You should reformat the code; rename the procedure, parameters, and variables; and simplify any unnecessarily complicated code.
b. Write 6P-style documentation for the code.
c. Explain how the code achieves its purpose.
Topics: lists of drawings
Write a procedure (diamond-of-circles num) which takes an integer num as a parameter and returns a drawing of a diamond consisting of circles around its perimeter. The parameter num is at least 2 and is the side length of the diamond. Each edge of the diamond must be composed of num evenly spaced black unit circles with one circle at each corner of the diamond. The leftmost and topmost edges of the compound drawing must be at 0 and 0, respectively.
Below are a few samples of the procedure.
> (image-show
(drawing->image
(scale-drawing 10
(diamond-of-circles 5))
100 100))

> (image-show
(drawing->image
(scale-drawing 10
(diamond-of-circles 10))
200 200))

We will post answers to questions of general interest here while the exam is in progress. Please check here before emailing questions!
in-bounds? return #t or #f if a drawing touches the boundary?Some of the problems on this exam are based on (and at times copied from) problems on previous exams for the course. Those exams were written by Charlie Curtsinger, Janet Davis, Rhys Price Jones, Samuel A. Rebelsky, John David Stone, Henry Walker, and Jerod Weinman. Many were written collaboratively, or were themselves based upon prior examinations, so precise credit is difficult, if not impossible.
Some problems on this exam were inspired by conversations with our students and by correct and incorrect student solutions on a variety of problems. We thank our students for that inspiration. Usually, a combination of questions or discussions inspired a problem, so it is difficult and inappropriate to credit individual students.