Due: 8:00 a.m., Tuesday, 2 October 2007
No extensions!
Summary: In this assignment, you will further explore the construction and use of spot lists.
Purposes: To give you experience thinking
about lists of
spots. To give you experience with map.
Expected Time: One to three hours.
Collaboration: I 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 me your answer. More details below.
Warning: So that this assignment is a learning experience for everyone, I may spend class time publicly critiquing your work.
Contents:
In the lab on lists and the lab on list iteration, you experimented with creating and manipulating spots, triplets of the form (column row position). We've seen how to draw a sequence of spots, to enlarge spots (and draw a sequence of enlarged spots), and even to translate lists of spots.
Of course, some people have difficulty coming up with interesting collections of spots. Hence, we might write procedures to help us do so.
Please write your procedure definitions in the Definitions pane. Before you begin, copy the following useful definitions from the labs into your Definitions pane.
(define spot.new
(lambda (col row color)
(list col row color)))
(define spot.col
(lambda (spot)
(car spot)))
(define spot.row
(lambda (spot)
(cadr spot)))
(define spot.color
(lambda (spot)
(caddr spot)))
(define spot.draw
(lambda (spot image)
(image.set-pixel! image (spot.col spot) (spot.row spot) (spot.color spot))))
(define spot.decadraw
(lambda (spot image)
(region.compute-pixels!
image
(* 10 (spot.col spot)) (* 10 (spot.row spot))
(+ 9 (* 10 (spot.col spot))) (+ 9 (* 10 (spot.row spot)))
(lambda (pos) (spot.color spot)))))
(define spot.htrans
(lambda (spot offset)
(spot.new (+ offset (spot.col spot)) (spot.row spot) (spot.color spot))))
(define spot.vtrans
(lambda (spot offset)
(spot.new (spot.col spot) (+ offset (spot.row spot)) (spot.color spot))))
(define spot-list.draw
(lambda (spots image)
(foreach! (r-s spot.draw image) spots)))
(define spot-list.htrans
(lambda (spots offset)
(map (r-s spot.htrans offset) spots)))
(define spot-list.vtrans
(lambda (spots offset)
(map (r-s spot.vtrans offset) spots)))
a. Write a procedure, (image.get-spot image pos), that gets the spot that corresponds to the given position in the image.
That is, if the color of image at position (col,row) is
color, then image.get-spot will return
(col row color).
b. Write a procedure, (image.get-spots image list-of-positions), that gets a list of spots from an image, using a list of positions
to indicate which spots to get. Note that you can write this using
map and image.get-spot.
Some of you
have asked questions about how we can make a list of positions to test
our procedure. We can create new positions using (position.new col row), and put those positions in a list, like so:
> (position.new 10 15)
655375
> (define list-of-positions (list (position.new 10 15)
(position.new 11 15)
(position.new 10 16)
(position.new 11 16)))
list-of-positions
> (map position.col list-of-positions)
(10 11 10 11)
> (map position.row list-of-positions)
(15 15 16 16)
> ; now let's test our procedure
> (define picture (image.load "/home/davisjan/Desktop/bsci.jpg"))
picture
> (define spots (image.get-spots picture list-of-positions))
spots
> (map spot.color spots)
(1604312319 1621155327 1671552255 1654709759)
> (map (compose rgb->string spot.color) spots)
("95/159/220" "96/160/221" "99/161/220" "98/160/221")
c. Write a procedure, (position.right-of pos offset), that, given a position and an offset, finds the position offset columns to the right of pos. For example,
> (position.right-of (position.new 10 10) 23)
2162698
> (position.col (position.right-of (position.new 10 10) 23))
33
d. Write a procedure, (position.row-of-ten pos), that,
given a position, makes a list of the ten positions in a row, starting
at pos and going to the right. For example,
> (position.row-of-ten (position.new 10 10))
(655370 720906 786442 851978 917514 983050 1048586 1114122 1179658 1245194)
> (map position.col (position.row-of-ten (position.new 10 10)))
(10 11 12 13 14 15 16 17 18 19)
Your procedure might look something
like the following. Or, you can write it more concisely using map.
(define position.row-of-ten
(lambda (pos)
(list pos
(position.right-of pos 1)
(position.right-of pos 2)
...)))
e. Write a procedure, (image.get-row-of-ten-spots image starting-pos), that gets ten spots in a row from
image, starting at starting-pos. You should use
image.get-spots and position.row-of-10 to build
this procedure.
f. Using image.get-row-of-ten-spots, grab a few rows from
an image of your choice and then draw them again (offset horizontally and
vertically) in a new image.
I will primarily look to see that your code is correct and uses appropriate style. I will also consider
whether you've found a way to use image.get-row-of-ten-spots
to draw interesting images.
Please submit this work via email. The email should be titled CSC151 HW8 and should contain your answers to all parts of this assignment.
Please send your procedure definitions as the body of an email message. You should also attach your source image, your result image, and the code you used to create the result.
Janet Davis (davisjan@cs.grinnell.edu)
Created September 29, 2007 based on http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007F/Assignments/assignment.08.html