Quiz #2 - 9/16/2004
Scheme drawing functions
Submit your solutions to this quiz by emailing them to Eric (our
TA) at meisne@cs.rpi.edu. You must send your email during the class
period (we won't grade anything sent after the quiz is over). Please let us
know if you have any problems sending your answers!
|
Overview: Drawing a checkerboard |
|
|
This quiz involves the development of number
of drawing functions, you must write each function listed here to get
full credit!. It is possible to draw an entire checkerboard using only
one function, but this quiz requires that you build a series of
increasingly useful functions. The final result is a function that
will draw a checkerboard like the one shown here.
|
|
Function to draw a square |
|
Create a scheme function named draw-square that
consumes a posn structure, a number and a symbol and
draws a square using the graphs primitives defined in the
draw teachpack (listed
in section 6.2 of the text).
The function draw-square should create a colored square on
the canvas with the upper left corner given by the first argument (a
posn structure). The second argument is the width of the square
(which is also the height) and the third argument is a symbol that
is used as the color. Here is an example of how this function could
be called, and the result:
;; create a canvas
(start 200 200)
;; draw a red square at 50,50 with sides of length 100
(draw-square (make-posn 50 50) 100 'Red)
|
|
|
Function to draw 2 squares next to each other |
|
Create a scheme function named draw-2squares that
consumes a posn structure, a number and and 2 symbols.
The function will draw 2 squares using the draw-square
function you wrote in part 1.
The function draw-2squares creates a colored square on
the canvas with the upper left corner given by the first argument (a
posn structure) using the width and the first color. The function
should then draw another square adjacent to the first (on the right
of the first square) but using the second color specified.
Here is an example of how this function could
be called, and the result:
;; create a canvas
(start 200 200)
;; draw a red square at 50,50 with sides of length 50, then a
;; black square at 50,100.
(draw-2squares (make-posn 50 50) 50 'Red 'Black)
|
|
|
Function to draw a 2x2 grid of alternately colored squares |
|
Create a scheme function named draw-2x2 that
consumes a posn structure, a number and and 2 symbols.
The function will draw a total of 4 squares, by calling the
draw-2squares function twice.
The function draw-2x2 creates a colored square on
the canvas with the upper left corner given by the first argument (a
posn structure) using the width and the first color. The function
should draw another square adjacent to the first (on the right
of the first square) but using the second color specified. The
function should also draw 2 squares adjacent to the first two, but
below them using the colors in the opposite order (see picture below).
Here is an example of how this function could
be called, and the result:
;; create a canvas
(start 200 200)
;; draw a 2x2 grid of squares in red and black
(draw-2x2 (make-posn 50 50) 50 'Red 'Black)
|
|
|
Function to draw a 4x4 grid of squares with alternating colors |
|
Hopefully you get the general idea here... Now use
draw-2x2 to draw a 4x4 grid and name the function that
does this draw-4x4
.
;; create a canvas
(start 300 300)
;; draw a 4x4 grid of squares, each 50 pixels wide (using red and black).
(draw-4x4 (make-posn 50 50) 50 'Red 'Black)
|
|
|
Function to draw an 8x8 checkerboard |
|
Use draw-4x4 to generate a complete checkerboard
with 8 squares on each row, column.
;; create a canvas
(start 600 600)
;; draw an 8x8 checkerboard in red and black with 50 pixel squares.
(draw-8x8 (make-posn 100 100) 50 'Red 'Black)
|
|
Submit your code (the definitions for all of the above functions)
as a single program. There is no need to include a call of any
functions, we will add that when testing your code (we will test each
function). Send your submission to meisne@cs.rpi.edu. Feel free to
add any notes that indicate how far you got (if you don't get
everything done).