Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 108
  • Last Modified:

avoiding darker colors

hi experts
In my javascript code i am using

colors[item] = '#' + Math.random().toString(16).slice(2, 8);

Open in new window

to generate a random color.

But sometimes the color generated is black which i dont want.
Is there anyway i can avoid black or darker colors?

thanks.
0
royjayd
Asked:
royjayd
1 Solution
 
Jan LouwerensCommented:
You can try generating the values in the HSV color space, then converting them into the RGB color space.
Another option would be to normalize the randomly generated RGB values.

Either way, you'd have to generate each color value separately, rather than all at once.
0
 
Tom BeckCommented:
If you are not concerned with including EVERY light color among the 16 million possibilities you could just limit the script so that it returns just the higher hex digits. You would still have millions of possible combinations.

jsfiddle:

http://jsfiddle.net/w7p9aora/
0
 
royjaydAuthor Commented:
thanks,
Any help with this question will be greatly appreciated.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28511714.html#a40304512
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now