Assignment 3: Drawing Generally and Concisely


Due: 10:30 p.m. Tuesday, 4 February 2014

Summary: In this assignment, you will experiment with drawing shadows and checkerboards. You will also write a procedure to draw an interesting picture that is scaled to a given width and height.

Purposes: To further practice with the drawings-as-values model. To consider concise algorithms for creating images with repetitive elements. To consider methods for scaling images to a given width and height. To gain experience writing procedures.

Collaboration: You must work with assigned partners on this assignment. The partner assignments are available at http://www.cs.grinnell.edu/~weinman/courses/CSC151/2014S/partners.html#2. You must collaborate on every problem - do not break up the work so that one person works on problem 1, another on problem 2, and another on problem 3. (The “"don't break up the work” policy applies on every assignment. This note is just a reminder.) You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.

Expected Time: Two to three hours. After two-and-a-half hours, stop what you're doing, write up what you've accomplished so far (which should take you less than half an hour) and write at the top of your assignment “I spent nearly three hours on this assignment. There's more to life than computer science!”. Doing so will earn you at least a check on this assignment if your group also visits with me in office hours to discuss the stumbling blocks you seem to have encountered.

Submitting: Email your answer to . The title of your email should have the form CSC-151-01 Assignment 3 and should contain your answers to all parts of the assignment. Scheme code should be in the body of the message. You should not attach any images; I should be able to re-create them from your code.

Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.

Preliminaries

You will need some of the code from the lab on procedures to test the examples given in this assignment.

Assignment

Problem 1: Adding shadows

a) Define a procedure that corresponds to the following documentation. Include this documentation along with your definition of the procedure.

;;; Procedure:
;;;   shadow
;;; Parameters:
;;;   drawing, a drawing
;;; Purpose:
;;;   Create a shadow for drawing.
;;; Produces:
;;;   my-shadow, a drawing
;;; Preconditions:
;;;   No additional.
;;; Postconditions:
;;;   my-shadow is the same size as drawing.  That is.
;;;     (drawing-width my-shadow) = (drawing-width drawing)
;;;     (drawing-height my-shadow) = (drawing-height drawing)
;;;   my-shadow is the same "shape" as drawing.  
;;;   my-shadow is colored grey.  
;;;   my-shadow is shifted up by 3 units and left by 6 units
;;;     relative to the position of drawing.  That is,
;;;     (drawing-left my-shadow) = (- (drawing-left drawing) 6)
;;;     (drawing-top my-shadow)  = (- (drawing-top drawing) 3)

Here are some examples of applying this procedure.

(shadow red-eye)

(shadow (hshift-drawing 10 blue-i))

b) Define a procedure (pair-with-shadow drawing) that groups a drawing together with its shadow. The shadow should appear behind. For example,

(pair-with-shadow (hshift-drawing 20 (vshift-drawing 20 red-eye)))

(pair-with-shadow (hshift-drawing 20 (vshift-drawing 20 blue-i)))

c) Document pair-with-shadow using the 6Ps.

Problem 2: Drawing a checkerboard, concisely

Using the drawings-as-values model, write a program to create a drawing of a checkerboard called checkerboard. Your drawing, when rendered, should give an 8x8 grid of squares in alternating black and red colors; each square should have a side length of 32. Your code should take advantage of the many similar elements in this figure.

We should be able to render your checkerboard drawing with the following command.

> (image-show (drawing->image checkerboard 256 256))

Recall that the drawings-as-values model includes procedures such as scale-drawing, hshift-drawing, recolor-drawing, and drawing-group.

Problem 3: Colorforms

You may recall Colorforms (r) from your childhood. These are simple colored shapes that you put together to make abstract images or somewhat representational images. (Most kids tend to make representational images.) The drawings-as-values model gives you a somewhat more powerful version of Colorforms, as you can choose the size and color of the shapes, and are not limited to what they provide. (On the other hand, you lose the cool triangles.)

a) Document and write a parameterized procedure to make an interesting representational image (a face, a house, a dog, whatever) using the drawings-as-values model.

You must include width and height parameters so that someone can call your procedure to make a drawing of the appropriate size.

You must include at least one other parameter of your choice, such as the color of some part of the drawing, or perhaps the relative size of some part of the drawing.

b) Include a command that creates an image combining at least two copies of your picture (i.e., two calls to the procedure from part a).

Important Evaluation Criteria

The first criterion we will use in evaluating your work is correctness. In particular, we will check to ensure that each program or procedure generates an appropriate image.

The second criterion we will use in evaluating your work is conciseness. That is, we will look to see whether your code is short or long for the problem. We will not differentiate short and long variable names, so please use comprehensible names.

The final criterion we will use in evaluating your work is generality. That is, for questions where you are asked to write a procedure, we will look at whether your procedure behaves correctly in a variety of situations.

Extra credit opportunity

We will award extra credit for the most concise code to construct a checkerboard.


Jerod Weinman

Copyright © 2007-2012 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.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License .