Based on a handout by Eric Roberts
Handouts:
Graphics Reference
Worked Example:
8Ball,
Day3: RandomCircles.java
Write a GraphicsProgram that draws a set of ten circles with different sizes, positions, and colors. Each circle should have a randomly chosen color, a randomly chosen radius between 70 and 200 pixels, and a randomly chosen position on the canvas, subject to the condition that the entire circle must fit inside the canvas without extending past the edge. The following sample run shows one possible outcome:
On some runs of this program you might not see ten circles. Why?
To generate random numbers create a RandomGenerator instance variable (a variable declared outside all methods) like so:
private RandomGenerator rgen = new RandomGenerator();
You can then use the variable to generate random numbers.
rgen.nextInt(min, max) //generates a random int in the range (min, max)
rgen.nextColor() //generates a random Color
If you finish early, consider making random doughnuts.