CPSC 120: Lab Assignment 4

Due the beginning of class on Friday, 03/25/2016

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

Overview

The goal of this assignment is to solidify your skill with defining methods and effectively using calls to those methods in various contexts. You will construct a surprisingly substantial program, based on the bubbles.pde program from the Example Code and the two sketches your made for Lab 3.

Begin by studying the Tutorial on Method Definitions, which you'll find in the Notes section of our class website. It will give you the framework you need to successfully complete the exercises.

Your Job

Part One

Begin by recalling your mondrian and circle drawings from Lab #3.

You are to write a program with two methods: mondrian and retroCircs. Each one should take four int values. A call to mondrian(x1,y1,x2,y2) draws your Lab 3 Mondrian design in the rectangle bounded by (x1,y1) and (x2,y2), with all components drawn proportional to this rectangle. Similarly, a call to retroCircs(x1,y1,x2,y2) draws your circle design—complete with bouncing balls!— with all parts proprtional to the rectangle defined by (x1,y1) and (x2,y2).

UPDATE (03/25/2016)

Per today's lab, only the Mondrian method is required for turn-in. The bouncing balls example may also be turned in for extra credit, equal to 50% of a standard lab grade (i.e. 25 points instead of 50).

Part Two

Modify the example program above to draw either your Mondrian or circle design, whenever the user clicks, drags, and releases the mouse.

Bonus excellence

You can switch back and forth between the two designs by adding a global variable that determines which drawing to use, defining a keyPressed that switches values of this variable, andmodifying the mouseReleased method to use this value. Begin by declaring a global int variable, which you initialize to 0. Let's call it "useMondrian". Then make these modifications:

void keyPressed() {
    if (useMondrian == 0) {
        useMondrian = 1;
    else {
        useMondrian = 0;
    }
}

void mouseReleased() {
    if (useMondrian == 0) { ... }
}

Save your sketch in the lab4 folder of your turn-in directory.

Extra Credit

Add a bubbles() method, based on the bubbles.pde program, on the Example Code page.


Turn In

Make a folder in your turn in directory named "lab4". Copy both of your solutions in to this folder. Consult the Linux tutorial from Lab #0 if you need a reminder of the details.


Standards

John H. E. Lasseter