posted 23 years ago
Ankush,
The Color class has many different constructors. The two which are easiest to use are Color( int r, int g, int b) where r, g, and b are ints in the range 0-255, and Color( float r, float g, float b) where r, g, and b are floats in the range 0.0-1.0.
Using the Math.random() function, you could either say:
int x = ( int )Math.random() * 255;
int y = ( int )Math.random() * 255;
int z = ( int )Math.random() * 255;
Color randomColor = new Color( x, y, z );
// or...
float x = ( float )Math.random();
float y = ( float )Math.random();
float z = ( float )Math.random();
Color randomColor = new Color( x, y, z );
Note that in either case, you have to cast the value produced by Math.random() to the desired value, since it normally produces a double greater than or equal to 0.0 and less than 1.0.
Hope this helps...
~Ryan
<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>