Created
March 30, 2015 18:59
-
-
Save kenechiokolo/7539e3f6ec79a3a0c3c3 to your computer and use it in GitHub Desktop.
CS106A Assignment 3.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import acm.graphics.*; | |
import acm.program.*; | |
import acm.util.*; | |
public class randomCircles extends GraphicsProgram { | |
// specifies number of circles | |
private static final int NCIRCLES = 10; | |
// specifies minimum radius | |
private static final int RMIN = 5; | |
// specifies maximum radius | |
private static final int RMAX = 50; | |
public void run() { | |
// creates n = NCIRCLES of random size, position and colour, wholly within the graphics window | |
for (int i = 0; i < NCIRCLES; i++) { | |
int rRandom = rgen.nextInt(RMIN, RMAX); | |
int x = rgen.nextInt(0, getWidth() - rRandom*2); | |
int y = rgen.nextInt(0, getHeight() - rRandom*2); | |
GOval circle = new GOval (x, y, rRandom*2, rRandom*2); | |
circle.setFilled(true); | |
circle.setFillColor(rgen.nextColor()); | |
add(circle); | |
} | |
} | |
// creates an instance of type RandomGenerator called rgen | |
private RandomGenerator rgen = RandomGenerator.getInstance(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment