Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

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.
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER