Functional Problem Solving (CSC 151 2015F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
Please be careful with your arguments about the number of possible images.
I had one group write that because they used (modulo n 4), (modulo n 10),
and (modulo n 25), they had 41025 different images.
Although you will get full credit on the "different images" criterion if you
just use n to compute 1 of 1000 different color schemes, you are likely to
find your project more interestsing if you use n for multiple aspects of
your image.
Make sure to document your procedures.
Make sure to name your procedures well.
Make sure that your code is elegant.
Here's a procedure that violates all three of the prior rules.
(define first-digit
(lambda (n)
(let ([number (remainder (remainder n 100) 10)])
(cond [(equal? 0 number)
12]
[(equal? 1 number)
11]
[(equal? 2 number)
10]
[(equal? 3 number)
9]
[(equal? 4 number)
8]
[(equal? 5 number)
7]
[(equal? 6 number)
6]
[(equal? 7 number)
5]
[(equal? 8 number)
4]
[else
3]))))
Better
;;; Procedure:
;;; third-digit
;;; Parameters:
;;; n, an integer in the range 0...999.
;;; Purpose:
;;; Compute the rightmost digit in n.
;;; Produces:
;;; digit, an integer in the range 0..9.
(define third-digit
(lambda (n)
(remainder n 10)))
;;; Procedure:
;;; recursion-depth
;;; Parameters:
;;; n, an integer in the range 0...999.
;;; Purpose:
;;; Compute the recursion depth we use for image n in our series.
;;; Produces:
;;; depth, an integer in the range 3 .. 12.
(define recursion-depth
(lambda (n)
(- 12 (third-digit n))))
(define source-image
(lambda (number)
(cond [(equal? 0 number)
"new-york.jpg"]
[(equal? 1 number)
"chicago.jpg"]
[(equal? 2 number)
"grinnell.jpg"]
[(equal? 3 number)
"paris.jpg"]
[(equal? 4 number)
"paris-again.jpg"]
[(equal? 5 number)
"boston.jpg"]
[(equal? 6 number)
"hub.jpg"]
[(equal? 7 number)
"tokyo.jpg"]
[(equal? 8 number)
"ellay.jpg"]
[else
"twin-cities.jpg"])))
You could make that much more elegant using a vector and vector-ref.
You could also make that more elegant by naming your files "city-#.jpg"
and using (string-append "city-" (number->string number) ".jpg").
While you may use gimp-image-resize (or whatever it's called) to resize
your original images if you are copying from existing images, you may not
use it after using any of the other operations.
You might find it useful to put the image number in the lower-right-hand corner of the image. You can use the following procedure to do so. (And no, you may not claim that because you get a different number on every image, it's a different image.)
;;; Procedure:
;;; image-label!
;;; Parameters:
;;; image, an image
;;; label, a non-negative integer
;;; color, a color
;;; Purpose:
;;; Adds a label to the lower-right-hand corner of the image.
;;; Produces:
;;; [Nothing; called for the side effect]
;;; Preconditions:
;;; 0 <= n < 1000
;;; 1 <= fontsize < 100
(define image-label!
(lambda (image label color)
(let* ([width (image-width image)]
[height (image-height image)]
[tmp (string-append "00" (number->string label))]
[str (substring tmp (- (string-length tmp) 3))])
(context-set-fgcolor! color)
(context-set-font-name! "Monospace Bold")
(context-set-font-size! (quotient (min width height) 15))
(image-display-text! image
str
(* .99 width) (* .99 height)
ALIGN-RIGHT ALIGN-BOTTOM)
(context-update-displays!)
image)))
Be careful about naming. Remember that the name of the procedure
you are supposed to write is (image-series n width height).
You can use the grading rubric as a check list.
Do you care if the helper procedures are local or not? And if they are similar, can I write one set of documentation?
;;; Procedures:
;;; add-fish!
;;; add-zorro-stripe!
;;; add-annoying-professor!
;;; add-nothing!
;;; Parameters:
;;; image, an image
;;; n, an integer in the range 0..999
;;; Purpose:
;;; Add the obvious things to the image
;;; Produces:
;;; [Nothing; called for the side effect.]
Writeup is exercise 3.