_GENERIC
Due: &_GENERIC-due;
Summary:
This assignment contains some problems I removed from miscellany01. Some
of these may move to an exam or elsewhere.
Purposes:
Expected Time:
Two to three hours.
Collaboration:
We encourage you to work in groups of size three. You may, however,
work alone or work in a group of size two or size four. You may discuss
this assignment with anyone, provided you credit such discussions when
you submit the assignment.
Submitting:
Email your answer to &grader-email;. The title of your email
should have the form &_GENERIC-subject; and
should contain your answers to all parts of the assignment. Scheme code
should be in the body of the message.
Warning:
So that this assignment is a learning experience for everyone, we may
spend class time publicly critiquing your work.
Assignment
Problem 3: A Rainbow of Images
As you may recall, the rgb-redder procedure makes
a color redder by adding a fixed value to the red component of the color.
Is this the only way we can make a color redder? Certainly not. We
could also make a color redder by averaging that color with red.
Consider the following procedure that averages two colors.
(define rgb-average
(lambda (rgb1 rgb2)
(rgb-new (/ (+ rgb-red rgb1) (rgb-red rgb2) 2)
(/ (+ rgb-green rgb1) (rgb-green rgb2) 2)
(/ (+ rgb-blue rgb1) (rgb-blue rgb2) 2))))
Write the most concise instructions you can to build seven copies of an
image, in which each copy is created by averaging each pixel with one
of the seven basic colors of the rainbow (red, orange, yellow, green,
blue, indigo, and violet). For example, in the orange variant, you
would use rgb-average to average each pixel with
the color orange.
Problem 6: Growing Polygons
Write a procedure, (turtle-growing-polygon!
turtle initial-side-length
sides length-increment
copies), that draws the given number
of copies of the specified polygon, with each copy drawn with a
side length length-increment larger than
the previous side.
Problem 8: Selecting Interesting Shapes
In the lab on iteration,
we saw that it was possible to use for-each and
the GIMP tools procedures to build compound images similar to those
we built using map and the drawings as
values
model, but with the added benefit that we could stroke
rather than select. In that example, we explored the following code.
> (define world (image-show (image-new 200 200)))
> (image-select-nothing! world)
> (for-each (lambda (left top)
(image-select-ellipse! world ADD left top 12 10))
(map (l-s * 10) (iota 20))
(map (l-s * 9) (iota 20)))
> (image-stroke! world)
> (image-select-nothing! world)
Write a set of instructions to stroke the outside of a
figure like the following (which we created in the reading on
homogeneous lists). Your instructions should not cut off
the bottom edge of the figure.
Important Evaluation Criteria