CPSC 120: Lab Assignment 2

Due at the start of class on Friday, 02/12/2016

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

Problems:

The following are all variations of the girad and triangle examples we did in class on Wednesday, 02/03/2016. You can get copies of those sketches from the Example Code section of our class web site. It probably goes without saying, but you should use loops to accomplish much of the work here. One way to know that you've done this correctly is to change the number of rows and columns from 20 to 10, then try another version with 30 rows and columns. The results should look roughly the same, no matter what row/column values you use.

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

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 "lab2". 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