In this assignment you will write a method for the
Add a (non-mutating) method called public Picture rainDrops()This method should draw non-overlapping, randomly located circles with random diameters between 5 and 20 pixels. The circles should be drawn on the Graphics object that comes from the Picture object that the method was called on (see page 217 of the textbook). This method should keep drawing non overlapping circles until either the circles cover 60% of the area of the picture or a maximum of 3,000 circles are drawn.
To help you get a sense of what this method should do, in the C:\java -jar raindrops.jarIf you run the program this way, it will also show you some interesting information in the console window. When you run this program, be sure to click on the "re draw" button and also try resizing the window, in particular, maximize the window to cover your whole monitor. (Your method does not need to implement a "re draw" button and your method does not have to deal with the Picture object being resized.)
Here is some information about writing this method.
Notice that a randomly chosen circle has three (random) parameters, two location coordinates (for the center) and a diameter. (Make sure that each of your non overlapping circles has its center within the borders of the picture.) Your method will need to keep track of the non-overlapping circles that it has generated and drawn on the picture. It needs this information so that it can compare a new (random) circle to the previously drawn ones and make sure that the new circle does not overlap with any of the previous circles. So for each non overlapping circle that has been drawn, your method must remember its two center coordinates and its radius. Store this information in three arrays called When your method generates a new random circle, it must test that circle to see if it overlaps with any of the circles already drawn on the picture and stored in the three arrays. So you need to figure out how to test if two circles do not overlap. If the new circle does overlap with a previous circle, you must discard the new circle's information and try again at generating a new random circle. If the new random circle does not overlap with any previous circle, then draw the new circle, store its information in the three arrays, increment a counter that is keeping track of how many circles you have drawn (and how many circles are stored in the arrays) and then compute the area of the new circle and add its area to a variable that is keeping track of the total area of all the drawn circles. Stop when the area of the drawn circles is 60% of the area of the picture (or when there are 3,000 circles in the picture).
You draw a circle using the
Write a program called
Turn in a zip file called |