CPSC 120: Assignment 3

Due at 2:59 pm on Monday, 10/28/2013

Home | Announcements | Assignments | Example Code


You will complete three problems for this assignment: bubbles, circles, and connect. All three should be in a folder named "hw3".


Problem #1

Complete the program below, bubbles.pde, which draws filled circles of random size and at random positions in the unit square (i.e. the default stddraw window). The method should take four arguments: the number of bubbles to draw, the probability that each bubble is colored with an determined "A" color value (versus a second, "B" color), the minimum radius of a bubble, and the maximum radius. Here are some sample calls with associated output:

bubbles(100, 0.75, 40, 50)
bubbles(50, 0.75, 40, 80)
bubbles(1000, 1.0, 4, 4)


Here is the program you must complete. NOTE: You cannot modify the draw() or setup() definitions, at all.

float probColorA = 0.0;

void setup() {
  size(500, 500);

void draw() {
  int minSz = (int) random(1, 100);
  int maxSz = (int) random(minSz, 100);

  bubbles((int) random(50, 1000), probColorA, minSz, maxSz);

  probColorA = probColorA + 0.1;
  if (probColorA >= 1.0) {
    probColorA = 0.0;

Problem #2

Complete the, circles.pde program, below, which draws n points, evenly spaced around a circle:

int n = 3;

void setup() {
  size(500, 500);

void draw() {
  n = n + 1;

Every few seconds, n increases by 1, and the image is redrawn. Your job is to define the circleplot function:



Problem #3

Extend your circles.pde sketch into a new program, connect, which plots dots as before, but then also draws lines between each point on the circle, with some probability, p.

The core of this is a function, connect, which takes as arguments an integer, n and a floating point value, p. The method should plot n points, evenly spaced around a circle. Then, for each pair of points, it should draw a gray line between them with probability p


Tip #1: This problem involves the drawing of n evenly-spaced points around a circle as a subproblem. That means you can reuse your circleplot solution here.

Tip #2: The key insight for the line drawing is to observe that from each point, we're going to consider every other point (what kind of control structure does this kind of nested iteration?). Then we *might* draw a line to it (with probability p). As a first attempt, try just drawing the lines. Then go back and study the comments on probability techniques, above.

Turn In:

As with all assignments for this course, submit the folder containing your Processing sketches. This should be a single folder named "hw3", which will contain your bubbles, circles, and connect sketches. You do not need to submit a paper printout of anything. Again, the turnin directory is


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).


John H. E. Lasseter