CS111, Wellesley College

Lab 4


Wedn September 26, 2007

Today:



EXERCISE 1: Escher Knitting Patterns

Please download the folder lab4_programs from the download directory on cs111 server.

Escher used two basic patterns to produce an amazing variety of patterns:


A(red,blue,green,yellow,magenta)


B(red,blue,green,yellow,magenta)

Below are three practice knitting patterns to figure out. The skeletons for the methods are in the LabKnitWorld.java file.

Your Task
Fill in the code for these methods to obtain the patterns. Consult Picture World contract if necessary.


labKnit1(Color.red, Color.green)


labKnit2(Color.magenta, Color.blue)


labKnit3(Color.blue, Color.red,
Color.cyan, Color.magenta)

 


EXERCISE 2: Simple QuiltWorld Patterns

First, a gentle introduction to quilting (Tasks 2a & 2b):

Task 2a Suppose you are given the following black box method:

public Picture triangle (Color c)
Returns a Picture of a triangle of the specified Color whose vertices are at (0,0), (1,0), and (0,1).

For example,


triangle(Color.green);

Using only the methods in the PictureWorld contract, write (on paper) the expressions which will return the following Pictures:


picture 1


picture 2


picture 3


Task 2b

Evaluate the following expressions. Draw (on paper) the Picture that each represents. Indicate the colors in whatever way is convenient (colored pencils, markers,etc.). Do not write a program to run on the computer to show you the pictures; do it by hand!

picture 4

overlay(clockwise90(triangle(Color.blue)),triangle(Color.blue));

picture 5

above(fourSame(flipDiagonally(triangle(Color.yellow))),
      beside(triangle(Color.green),
             above(empty(), flipVertically(triangle(Color.green)))));
Feel free to use local variables, to break the statement above to smaller, more manageable ones. Here is one way of doing so:
Picture p1 = triangle(Color.green);
Picture p2 = flipVertically(p1);
Picture p3 = above(empty(), p2);
Picture p4 = beside(p1, p3);

Picture p5 = flipDiagonally(triangle(Color.yellow));
Picture p6 = fourSame(p5);

Picture p7 = above(p6, p4);


Task 2c

Read about QuiltWorld in Problem Set 3. Below are two quilt designs for you to figure out. The skeletons for the methods are in the LabQuiltWorld.java file.


diamonds()


fourColors()