Due: 11 a.m., Wednesday, 15 October 2008
Summary: Practice three techniques for repetition you learned this week.
Purposes: Gain additional experience with
compose, interesting uses of
image-compute-pixels!, and basic list recursion.
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 <weinman>. The title of your email
should have the form HW6 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.
This assignment has three parts, based on three topics from the past week. The three parts are independent and may be completed in any order.
1. Implement a procedure
(.
This procedure should take an image and a weight as parameters and
produce a new image where each pixel is the weighted average of the
color from the original image and the color named
image-through-rose-colored-glasses
image weight)“rose”. Consider the following examples
using Professor Davis's StalkerNet image:
| Original | weight = 0.3 | weight = 0.7 |
![]() |
![]() |
![]() |
We have several hints for you:
image-variant to produce the new image.
rgb-weighted-average procedure. Think about
how to make use of that procedure here.
2. Generalize your procedure by allowing the user to specify what color
to use for the filter. Write a new procedure,
(.
The third parameter should be a string representing the name of a color.
image-color-filter
image
weight
colorname)
Here are a few examples.
| Original | weight = 0.5,
colorname = “sky blue” | weight = 0.7,
colorname = “sea green” |
![]() |
![]() |
![]() |
image-compute-pixels!3. Build the ugliest image you can (in one hour or less) using the ideas from the lab on building images by iterating over positions. Your image should include at least one blend, at least one striped shape, and at least one shape that is not a square or rectangle.
4. Imagine that map were not included in Scheme.
Could you implement it yourself? Certainly!
The map procedure can be implemented recursively.
In fact, this is a
procedure that we implemented ourselves for DrFu.
Using what you learned about list recursion this week, implement the
procedure (. Like my-map proc
lst)map,
your procedure should take as parameters a unary procedure and a list,
and produce a new list that contains the results of applying the
procedure to each item in the original list. Please document
my-map using the 6 P's format.
5. In the lab on recursion
basics, we asked you to implement a procedure
( that, given a list of colors,
counts how many are dark. How might we generalize this idea? A more
general procedure might take both a list and a predicate as parameters,
and count the number of items in the list for which the predicate is
true.
rgb-tally-dark
colors)
Implement a procedure (
that takes as parameters tally
pred? lst)pred?, a predicate
procedure, and lst, a list of values.
The procedure should return a non-negative integer representing the
number of items in lst for which
pred? is true.
For example,
>(tally even? (list 1 2 3 4 5))2>(tally odd? (list 1 2 3 4 5))3>(tally integer? (list 1 2 3 4 5))5>(tally symbol? (list 1 2 3 4 5))0
In evaluating your work, we will consider the correctness, conciseness, and elegance of your code and the documentation we asked you to write. In awarding pluses, we will also look at the creativity of your code in Part B; did you go beyond what was demonstrated in the lab?
Define and test a Scheme procedure,
(,
that takes a list as its
parameter and produces a list of two lists, one comprising the elements in
even-numbered positions in the given list, the other comprising the
elements in odd-numbered-positions.
unriffle lst)
>(unriffle (list 'a 'b 'c 'd 'e 'f 'g 'h 'i))((a c e g i) (b d f h))>(unriffle (list))(() ())>(unriffle (list 'a))((a) ())>(unriffle (list 'b))((b) ())>(unriffle (list 'a 'b))((a) (b))
Hint: There are many ways to solve this problem. Most of them involve a recursive helper procedure.