Solved

avoiding darker colors

Posted on 2014-09-05
3
99 Views
Last Modified: 2014-09-06
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
Comment
Question by:royjayd
3 Comments
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 40306969
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
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 40307057
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
 

Author Comment

by:royjayd
ID: 40307754
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now