Functional Problem Solving (CSC 151 2014F) : Labs
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Summary: In this laboratory, you will experiment with ways to build and use lists of drawings.
a. Make a copy of lists-of-drawings-lab.rkt, which contains some useful code for this lab.
b. Make a list (mental, on paper, or on the computer) of the procedures and values initially included in the file.
c. In your own words, explain the difference between
check-drawing and check-drawings.
Create each of the following drawings using the drawings-as-values model.
That is, use procedures like scale-drawing and
hshift-drawing.
a. sample-circle, a circle of diameter 8, centered at (0,50).
b. sample-square, a square of edge-length 6, centered at (0,25).
a. The reading claims that we can make a list of drawings with
(. Make and render a list of the two
drawings you created in the previous exercise.
list drawing1 ...
drawingn)
b. The reading claims that we can make a list of identical drawings with
the make-list procedure, as in the following.
>(make-list 5 "Hello")
Verify this claim.
c. Create a value, ten-circles, that consists of 10 copies
of sample-circle.
>(define ten-circles ...)
d. Have the Scheme interpreter print out that value to see whether it seems to contain the expected ten copies.
>ten-circles
e. What do you expect to have happen when we try to render
ten-circles with check-drawings?
f. Check your answer experimentally.
>(check-drawings ten-circles)
You may find it useful to look at the notes on this exercise.
As you may recall, (
builds a new list of drawings by horizontally shifting each element of
map
hshift-drawing
list-of-offsets
list-of-drawings)list-of-drawings by the corresponding elements
of list-of-offsets.
Consider the following sequence of instructions:
(define list01 (list 0 10 20 30 40 50 60 70 80 90)) (define list02 (list 10 25 33 45 60 100 110 111 112 120)) (define ten-circles-01 (map hshift-drawing list01 ten-circles)) (define ten-circles-02 (map hshift-drawing list02 ten-circles)) (define ten-circles-03 (map vshift-drawing list01 ten-circles)) (define ten-circles-04 (map vshift-drawing list02 ten-circles)) (define ten-circles-05 (map vshift-drawing list01 ten-circles-02)) (define ten-circles-06 (map hshift-drawing list01 ten-circles-01))
a. Where do you expect the circles in each list to fall?
b. Check your answers experimentally.
>(check-drawings ten-circles-01)>(check-drawings ten-circles-02)>(check-drawings ten-circles-03)>(check-drawings ten-circles-04)>(check-drawings ten-circles-05)>(check-drawings ten-circles-06)
a. As you may recall, ( makes a list of the numbers from 0 to iota n)n-1. Predict what (iota 10) is and check your answer experimentally.
b. What do you expect the result of the following to be?
>(check-drawings (map hshift-drawing (iota 50) (make-list 50 sample-square)))
Check your answer experimentally.
c. What do you expect the result of the following to be?
>(check-drawings (map hshift-drawing (iota 50) (map vshift-drawing (iota 50) (make-list 50 sample-square))))
d. What do you expect the result of the following to be?
>(check-drawings (map hshift-drawing (iota 50) (map vshift-drawing (reverse (iota 50)) (make-list 50 sample-square))))
e. What do you expect the result of the following to be? (You need not specify all the members of each list; just summarize.)
>(map mod7 (iota 50))>(map times5 (iota 50))>(map times5 (map mod7 (iota 50)))>(map mod7 (map times5 (iota 50)))
Check your answer experimentally.
f. What do you expect to get for each of the following?
>(check-drawings (map hshift-drawing (map times5 (iota 50)) (map vshift-drawing (map mod7 (iota 50)) (make-list 50 sample-square))))>(check-drawings (map hshift-drawing (map times5 (iota 50)) (map vshift-drawing (map times5 (map mod7 (iota 50))) (make-list 50 sample-square))))
Check your answer experimentally.
In the final stages of the previous exercise, we got a series of diagonals built by replicating an image. But what if we wanted something more “v-shaped”?
a. Let's start with a simple v. Using an appropriate
combination of iota, reverse,
append, map, and
increment, create the list
(0 1 2 3 ... 24 25 24 23 ... 3 2 1) and call it vee.
Hint: Try to think about how you systematically build the two halves of that list (the numbers in increasing order and then the numbers in decreasing order). Note that this list is not quite symmetrical. That's intentional.
b. Using the list vee, as well as (iota 50), build a
“V-shaped” sequence of circles called vee-circles.
c. Using the list vee, as well as (iota 50), build a
“>-shaped” sequence of squares called vee-squares.
Take any of your lists of fifty shapes from the previous exercises and arrange so that the first 10 shapes are colored blue, the next 15 are colored red, and the last 25 are colored green.
It is likely that you'll want to take two steps to this: First, build
a list of 10 copies of blue, 15 copies of red, and 25 copies of green.
(You can use make-list and append.)
Second, use map and recolor-drawing
to recolor the individual drawings.
Here is a rendering of a simple diagonal of unit squares.
>(check-drawings (map hshift-drawing (map times5 (iota 50)) (map vshift-drawing (map times5 (iota 50)) (make-list 50 drawing-unit-square))))
a. Update that sequence of drawings so that the squares range systematically
in edge length from 1 to 5. (That is the lengths will be 1, 2,
3, 4, 5, 1, 2, 3, 4, 5, ....) You'll need to build the list of lengths
and then use map to change the size of the
squares.
b. Update the first sequence of drawings so that the width of the rectangles ranges systematically from 1 to 5, but the height stays 1.
c. Update the first recent sequence of drawings so that the width of the rectangles ranges systematically from 1 to 5 and the height of the rectangles ranges systematically from 1 to 7.
You have now learned how to systematically shift, scale, and recolor copies of a single drawing. Put these different techniques together to create the most interesting drawing you can.