Solved

avoiding darker colors

Posted on 2014-09-05
3
100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

863 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

25 Experts available now in Live!

Get 1:1 Help Now