• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Random Colors???HELP!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was wondering if anyone could tell me which method would i use to randomly generate colors, when i am not sure how many times i need it generated.
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Annette,
The closest I've gotten to this is setting up an array of colours and cycling through them over and over. Though this isn't random, I suppose you could repeatedly generate a random number between 0 and the number of colours in the array to choose a colour at random.
I haven't tried to generate customised colours, but looking at the constructors in the Color class, it looks like you can feed in your own (randomly generated )numbers to make a colour. For generating random numbers, there's the Random class, and Math.random.
Constructor example from Color API
~~~~~~~~~
Color(int r, int g, int b, int a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
~~~~~~~~~
cheerio
rowan
 
Annette Pomeroy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help, I appreciate it much!
I will try what u have told me.
Thanks again,
Annette
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maby you could do something like this ..
Color ColorTest(){
int R = 0;
int G = 0;
int B = 0;
R = (int)(1+Math.random()*(255));
G = (int)(1+Math.random()*(255));
B = (int)(1+Math.random()*(255));
return new Color(R,G,B));
}
hope it helps ..
 
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic