CPSC 120: Assignment 2

Due at 2:59 pm on Friday, 09/20/2013

Home | Announcements | Assignments | Example Code

Overview

You will complete three problems for this assignment: ball1, ball2, and colorsquares2. All three should be in a folder named "hw2".

Reading

Problem #1

There's a fun optical illusion that arises from carefully drawing color gradations on concentric circles. The idea is to draw several concentric rings, with the outermost a very dark shade, and each successive inner one a lighter shade than the one that encloses it. The result is a sphere that appears to "glow" from its center.

Here are examples, using (respectively) 10, 20, and 60 consectuive rings:

   

Your job for this problem is to make a program that draws this "sphere". The color gradation and the number of rings are up to you. However, the color gradation must suggest this "glow", and it should be easy to change the number of rings, for more or less detail in the drawing. Save your source code in a sketch file named "ball1".

Some advice

Problem #2

Using the sphere-drawing techniques you developed for the first problem, create a second program that loads an attractive image, and animates an illuminated sphere, bouncing around the inside of the window:

Save your source code in a sketch file named "ball2".

Advice

This problem is actually pretty challenging. Fortunately, you've seen most of what you need to see in the recent in-class examples (the bouncing target, and the bouncing color line square). See the Example Code page for working copies of these programs.

Obviously, you're going to need a loop to draw the sphere. Because it's moving in the window, you're going to need to use this loop inside of the draw() definition. The most important things to keep in mind are these:

Problem #3

In Exercise 6-8 of your text, you're asked to create a grid of colored squares, where the colors are chosen randomly.

Modify this program in a sketch named colorsquares2, in which the squares change color every few seconds:

Advice

The only real requirements are that the colors change every few seconds and that they do so with some degree of randomness. As we saw in class, there are several variations available, by biasing the random generation of colors. For example, you can ensure a mostly bluish scheme with

r = (int) random(0, 150);
g = (int) random(0, 150);
b = (int) random(100, 255);

Other variations can be obtained by keeping variables for the minimum and maximum red/green/blue values, and letting those change over time. Or find a way to generate darker shades in one corner, lighter shades in another. Have fun with this one!

Turn In:

As in Assignment 1 (and all assignment for this course), submit the folder containing your Processing sketches. This should be a single folder named "hw2", which will contain your ball1, ball2, and colorsquares2 sketches. You do not need to submit a paper printout of anything. Again, the turnin directory is

~lasseter/classes/cpsc120/username

You may re-submit this work as many times as you like, up to the due date/time. Anything submitted after 3:59 pm on Thursday 09/26 will be considered late (and every file contains a time stamp).


Standards

John H. E. Lasseter