Functional Problem Solving (CSC 151 2014S) : Assignments

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/~rebelsky/Courses/CSC151/2014S/partners/assignment.03.html. 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.

Wrapper (Prologue): Individually read through this assignment and make sure that you understand what is required. Then use the form available at http://bit.ly/151hw3pro to indicate (a) how long you think this assignment will take and (b) what you think will be the most challenging aspect of this assignment.

Wrapper (Epilogue): When you are done with the assignment, fill out the form available at http://bit.ly/151hw3epi to indicate (a) how long the assignment took, (b) what the most challenging part of the assignment was, and (c) something important you learned from doing the assignment. If you find that the assignment took much less or much more time than you expected, also include (d) a note as to what might have led to that difference.

Submitting: Email your answer to . The title of your email should have the form CSC 151.02 Assignment 3: Exploring Drawings 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.


Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright (c) 2007-2014 Janet Davis, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials are copyright by John David Stone or Henry Walker and are used with permission.)

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.