I'm new to the forum as a member, but I have browsed through a few times looking over different tips. Anyway, I am currently doing a homework assignment and am not sure how to make a random color generator. I thought about creating a random number generator and making it psuedo random by assigning a color based on the integer the generator chooses. I was wondering if that is the easiest way or someone has other suggestions. I have hit a wall and can't seem to think of anything else. Any ideas would be greatly appreciated
/**
* Create a box with a user defined set of balls that bounce around the inside and off the walls.
*/
public void boxBounce(int numberOfBalls)
{
int ground = 400; //Ground position
int wall = 0; //wall position
myCanvas.setVisible(true);
//Draw the box
myCanvas.getSize();
Rectangle box = new Rectangle(20, 20, ((int)myCanvas.getSize().getWidth() - 40), ((int)myCanvas.getSize().getHeight() - 40));
myCanvas.draw(box);
//Create the balls and add them to an ArrayList
ArrayList<BallBoxBounce> balls = new ArrayList();
Random numGen = new Random();
Random colorGen = new Random();
for (int count = 0; count < numberOfBalls; count++)
{
if (numGen / 2 == true)
{
return even;
}
else
{
if (numGen / 2 == false)
{
return odd;
}
else
{
if (numGen / 3 == true)
{
return divByThree;
}
else (numGen == 1)
{
return isOne;
}
}
}
return 0;
BallBoxBounce ball = new BallBoxBounce(numGen.nextInt(350), numGen.nextInt(80), numGen.nextInt(50), Color.colorGen, ground, myCanvas);
}
}
}
EDIT - fixed the dumb bracket that wasn't enclosing the code tags.
This post has been edited by skim: 18 November 2008 - 09:31 PM

New Topic/Question
Reply




MultiQuote




|