CS 151: Project #1

### Project 1: Computational Thinking

The purpose of this assignment is to explore how we go about describing an algorithm, which is simply a series of steps in a process.

This is an exercise you need to do with a partner. For each of the tasks, one of you will be the artist and the other person the director. Switch roles for each new task (there are six, so each of you should get three chances at each role). While the description is a bit long, the exercise shouldn't take more than an hour. Each of you should read through the task completely before starting.

Get some graph paper...
1. Director: describe a simple logo or shape to the artist using 30 words or less. Write down your commands and then give it to the artist without any further explanation.

Artist: draw the shape as you interpret the directions

2. Director (swap roles from task 1): describe a simple logo or shape to the artist using 30 words or less, but you may use up to an additional 10 words per term to define each term in your original list of instructions.

Artist: draw the shape as you interpret the directions and definitions.

3. Director: your task is to describe a simple logo or shape to the artist using only commands from the set defined below. Label the paper with the commands as Shape A.

Artist: your task is to read and execute the commands written by the director. Do so as strictly as possible.

For this task command terms are:

1. Pen up
2. Pen down
3. Pen Forward 1 unit
4. Pen Turn left 1 angular unit
5. Pen Turn right 1 angular unit
6. Pen Goto point (x, y)

Before you begin, you need to discuss the meaning of each term. Write these meanings down. The artist may want to use a second pencil to point in the current direction, which is the direction in which the pen should move on a forward command.

Once you have agreed upon the meanings of each term, the director should describe a shape to the artist by writing a sequence of no more than 15 commands, where each command is one of the six terms above. The set of commands should leave the pen in the same position and orientation where it began.

For example, if we set the angular unit to 90 degrees, the following would be a set of commands that makes a rectangle and leaves the pen exactly where it started.

Label: Shape Z1
Pen down
Pen forward
Pen left
Pen forward
Pen forward
Pen left
Pen forward
Pen left
Pen forward
Pen forward
Pen left

4. Switch roles and repeat the prior task, but use a different shape. Write the second list of commands on a different piece of paper and label it Shape B.
5. For the next task, the director needs to tell the artist to make two copies of Shape A in different locations on the page. If you could use only the commands from the first task, how many commands would it take?

Instead of just copying the list of commands twice, however, we're going to make use of the Shape A and Shape B labels by adding a new term to our vocabulary: Execute list. If the director writes the command

Execute list Shape A

then the artist should pick up the paper labeled Shape A, follow all of the commands on it, then return to the command following the Execute list command. For example, the following series of commands would draw two copies of Shape Z1 one unit apart (try it out). We'll call this one Shape Q.

Label: Shape Q
Pen down
Execute list Shape Z1
Pen up
Pen forward
Pen forward
Pen down
Execute list Shape Z1

Director: write down a list of commands that makes at least one drawing of Shape A and one drawing of Shape B. Label this page as Shape C.

Artist: on a new piece of paper, follow the commands and draw the shapes.

6. The final task is to make your commands more flexible by enabling the director to specify how many units forward to traverse. For example, the command:

Pen forward 3

would tell the artist to draw forward 3 units. With this modification, the commands from shape Z1 could be written as follows.

Label: Shape Z2
Pen down
Pen forward 1
Pen left
Pen forward 2
Pen left
Pen forward 1
Pen left
Pen forward 2
Pen left

Adding one more feature to the commands gives us even more flexibility. Let's allow the director to assign a number to any single capital letter and then use that letter in place of a number later in the command list. For example, the following two lines would tell the artist to move the pen forward 5 units.

X = 5
Pen forward X

With this extension, we could easily change the size of the rectangle defined by the shape Z2 command list by just changing two numbers. In the example command list below, the size of the rectangle is determined by the values given to the symbols A and B.

Label: Shape Z3
A = 2
B = 5
Pen down
Pen forward A
Pen left
Pen forward B
Pen left
Pen forward A
Pen left
Pen forward B
Pen left

What if we assigned the values of A and B before executing Shape Z3? For example:

 Label: Shape Z4 Pen down Pen forward A Pen left Pen forward B Pen left Pen forward A Pen left Pen forward B Pen left Label: Shape Q Pen down A = 1 b = 2 Execute list Shape Z4 Pen up Pen forward 2 Pen down A = 2 B = 4 Execute list Shape Z4

When the artist draws Shape Q, then the first time Shape Z4 will have sides of length 1 and 2, while the second time, Shape Z4 will have sides of size 2 and 4.

Director: create a Shape D that is like Shape A or Shape B but uses one or more variables in the forward commands, just like Shape Z4 above. Then write a Shape E command list that makes two versions of Shape D of different size.

Artist: draw the shape, but be careful interpreting the commands so that each forward command goes the proper distance.

### Writeup

Each of you should create your own wiki page for your writeup. On the wiki, put a copy of the command lists you created as a director. If you're feeling ambitious, take a photo of your work as an artist and put up the pictures (cell phones work well).

Please put the label cs151s09proj1 on your writeup page (down below the editing window on the edit tab).