The HW 8 setup is the same as for HW 4.
Implement the function colors->lines, which takes a list of colors and a number n (representing the image width). It returns a list of color lists. Each result color list contains n consecutive colors from the original list. Thus, the result list of lists represents a list of image rows, where each row is a list of colors.
(colors->lines (list (make-color 1 2 3) (make-color 11 12 13) (make-color 21 22 23) (make-color 31 32 33) (make-color 41 42 43) (make-color 51 52 53)) 2) "should be" (list (list (make-color 1 2 3) (make-color 11 12 13)) (list (make-color 21 22 23) (make-color 31 32 33)) (list (make-color 41 42 43) (make-color 51 52 53)))
You can assume that the length of the color list is a multiple of n.
Implement image-plus, which is just like image+: it takes two images an adds the second on top of the first. You can assume that the second image is smaller than then first.
Naturally, you cannot use image+, offset-image+, or offset-masked-image+in your implementation. Pretend instead that you are a CS 2010 instructor supplying a teachpack to first-week students, and all you have for image processing is image-width, image-height, image->color-list, color-list->image, and the color functions.
Implement offset-image-plus, which is just like offset-image+: it takes an image, two offset numbers, and another image. You can assume that the second image is shorter than the first image minus the vertical offset, and it is narrower than the first image minus the horizontal offset.
As before, you cannot use image+, offset-image+, or offset-masked-image+. Furthemore, you must not handin an image-plus and offset-image-plus that contain cut-and-pasted code.
Implement offset-masked-image-plus, which is like offset-masked-image+. You can assume that the last image is shorter than the first image minus the vertical offset, and it is narrower than the first image minus the horizontal offset. You can also assume that middle and last images are the same size.
As before, you cannot use image+, offset-image+, or offset-masked-image+. Furthemore, you must not handin an image-plus, offset-image-plus, and offset-masked-image-plus that contain cut-and-pasted code.
Implement find-image?, which is like a combination of image-inside? and find-image: it takes two images and returns either a posn (indicating where the second image appears in the first) or false (indicating that the second image does not appear in the first).
Naturally, you cannot use find-image to implement your function. You can assume that the second image appears in the first.
This exercise is more difficult than all of the other exercises combined. Here are some hints:
;; andmap/short : (X Y -> bool) list-of-X list-of-Y -> bool ;; The second list can be shorter than the first (define (andmap/short COMP al bl) (cond [(empty? bl) true] [else (and (COMP (first al) (first bl)) (andmap/short COMP (rest al) (rest bl)))]))
;; down-one : num-or-false -> num-or-false (define (down-one p) (cond [(number? p) (add1 p)] [else p]))
;; right-one : posn-or-false -> posn-or-false (define (right-one p) (cond [(posn? p) (make-posn (add1 (posn-x p)) (posn-y p))] [else p]))
Last update: Wednesday, October 8th, 2003mflatt@cs.utah.edu |