# CPSC 120: Assignment 3

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

Home | Announcements | Assignments | Example Code

### Overview

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

• Learning Processing, Chapters 6 (loops) and 7 (Functions).

## 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);
background(255);
frameRate(0.2);
}

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);
background(255);
frameRate(0.4);
}

void draw() {
circleplot(n);

n = n + 1;
}
```

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

```circleplot(8)
circleplot(16)
circleplot(128)
```

## 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

```connect(16,0.05)
connect(16,0.125)
connect(16,0.45)
connect(16,1.0)
```

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