Comp 170 Lab 5 - Random Bubbles, Feb 22

Goals

Overview

A new project "Bubble" is available here, including the Circle class from very early on. You are to use it to draw 100 circles, with random center and random radius. You can even choose a random color; see below.

I have added a Circle constructor that takes the center coordinates (x,y) as parameter. The size of a Canvas drawing pane is here 500x400, so you should be sure to choose x and y in their respective ranges. To choose a random number in the range 0≤x<N, use
    x = rand.nextInt(N);
where rand is an object of class Random.

Provide a bubbles(int maxradius) method that takes a parameter representing the maximum radius. For your first try, choose the radius of each bubble in the range 0≤x<maxradius. Try this for maxradius=10 and maxradius=100. Note that this chooses all sizes equally, and for a max size of 100, the larger bubbles overwhelm the picture.

Now copy your bubbles method and modify it as follows. The bubbles2 method is to choose random bubbles with radius in the range 0..100, but to "prefer" the smaller ones. That is, we want to choose a radius in the range 0≤r<100, but with r more likely to be at the small end. Here's one way we can do that:

This should draw more smaller bubbles than larger. Cubing w would make the effect even more exaggerated. Can you again make maxradius a parameter?

I've provided you with a method numtocolor, which takes an n<6 and returns a color string. Use that and rand.nextInt(6) to choose a random color for each circle.

Email me your completed Bubble.java file.