Home |
Announcements |
Assignments |
Example Code

### Overview

### Reading

## Problem #1

## Problem #2

## Problem #3

### Turn In:

### Standards

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

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; } }

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)

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

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

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

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

Your code must be syntactically correct. Any solution that contains a syntax or type 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.