# CPSC 120: Lab Assignment 4

### Due at the start of class by midnight on Friday, 02/24/2017

Home | Calendar | Announcements | Assignments | Example Code | Notes

### Problems:

In each of the following four problems, you are to draw a triangular figure whose dimensions are determined by the current frame number. That means that each figure should be drawn inside a draw() method. You can slow the framerate down enough to observe your results by adding in your setup() method the command

`frameRate(0.2);  // a frame every 5 seconds`

The smallest dimension of each figure should be 2. The largest should be 100. When you have reached 100 frames, your sketch should reset the dimension of your figure to 2.

You may, but are not required to, play with the color of the squares, drawing inspiration. There are some fun possibilities here!

Needless to say, each figure will need a loop to draw it. In fact, you'll need to find a way to nest a loop inside of a loop!

The problems are described below. In each case, I've presented them as if the dimension was 20. It might help to solve it for this dimension first, before you try to tackle the framerate-based version.

1. Make a sketch that draws a 20 row by 20 column triangle, made out of small rectangles. The triangle should have a right angle that lies in the upper right corner of the sketch, and its width and height should be that of the window:

Save your work for this in a sketch called prob1.

2. Make a sketch that draws a 20 row by 20 column triangle, made out of small rectangles. This time, the triangle should have a right angle that lies in the lower left corner of the sketch, and its width and height should be that of the window:

Save your work for this in a sketch called prob2.

3. Make a sketch that draws a 20 row by 20 column triangle, made out of small rectangles. This time, the triangle should have a right angle that lies in the bottom right corner of the sketch, and its width and height should be that of the window:

Save your work for this in a sketch called prob3.

4. Make a sketch that draws an 19 row by 10 column triangle, made out of small rectangles. The long edge of the triangle should be against the left side of the window, one of its points should touch the right edge, and the height should be equal to (or almost equal to) that of the window:

(It may be a bit off, as in this illustration, because of the trancation error that exists in integer arithmetic.) Save your work for this in a sketch called prob4.

### Turn In

Make a folder in your turn in directory named "lab4". Copy all four of your solutions in to this folder. Please use exactly this name for the folder (in lowercase letters, no spaces), and please copy only the .pde files, not the folders they come in. This helps me with printing everything in a reasonable amount of time.

### Standards

• Your code must be syntactically correct. Any solution that contains a syntax error anywhere (and hence crashes when you hit the "play" button") will receive no credit.

If you run into any trouble here, please ask me or one of the TAs for help.

• Naturally, your code must be behaviorally correct, though partial credit is always given for partial solutions.

John H. E. Lasseter