CSC151.02 2010S Functional Problem Solving : Labs
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.01 2010S (Weinman)] [CSC151 2009F (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
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.scm
, 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.
a. sample-circle
, a circle of diameter 5, centered at (0,50).
b. sample-square
, a square of edge-length 4, 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
.
d. Have the Scheme interpreter print out that value to see whether it seems to contain the expected ten copies.
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
drawing-hshift
list-of-drawings
list-of-offsets
)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 drawing-hshift ten-circles list01)) (define ten-circles-02 (map drawing-hshift ten-circles list02)) (define ten-circles-03 (map drawing-vshift ten-circles list01)) (define ten-circles-04 (map drawing-vshift ten-circles list02)) (define ten-circles-05 (map drawing-vshift ten-circles-02 list01)) (define ten-circles-06 (map drawing-hshift ten-circles-01 list01))
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 drawing-hshift (make-list 50 sample-square) (iota 50)))
Check your answer experimentally.
c. What do you expect the result of the following to be?
>
(check-drawings (map drawing-hshift (map drawing-vshift (make-list 50 sample-square) (iota 50)) (iota 50)))
d. What do you expect the result of the following to be?
>
(check-drawings (map drawing-hshift (map drawing-vshift (make-list 50 sample-square) (reverse (iota 50))) (iota 50)))
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 drawing-hshift (map drawing-vshift (make-list 50 sample-square) (map mod7 (iota 50))) (map times5 (iota 50))))
>
(check-drawings (map drawing-hshift (map drawing-vshift (make-list 50 sample-square) (map times5 (map mod7 (iota 50)))) (map times5 (iota 50))))
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).
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 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 drawing-recolor
to recolor the individual drawings.
Here is a rendering of a simple diagonal of unit squares.
>
(check-drawings (map drawing-hshift (map drawing-vshift (make-list 50 drawing-unit-square) (map times5 (iota 50))) (map times5 (iota 50))))
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.
Primary: [Front Door] [Schedule] - [Academic Honesty] [Instructions]
Current: [Outline] [EBoard] [Reading] [Lab] - [Assignment]
Groupings: [Assignments] [EBoards] [Examples] [Exams] [Handouts] [Labs] [Outlines] [Projects] [Readings]
References: [A-Z] [By Topic] - [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [CSC151.01 2010S (Weinman)] [CSC151 2009F (Rebelsky)]
Misc: [SamR] [MediaScript] [GIMP]
Copyright (c) 2007-10 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)
This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
This work is licensed under a Creative Commons
Attribution-NonCommercial 2.5 License. To view a copy of this
license, visit http://creativecommons.org/licenses/by-nc/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.