How can I generate a random human readable color from the seed? FROM#

Got a log file and it has all sorts of text in it. It currently only displays as one color and each entry says something like:

Log from section 1: Some text here 
Log from section 125: Some text here 
Log from section 17: Some text here 
Log from section 1: Some text here 
Log from section 125: Some text here 
Log from section 1: Some text here 
Log from section 17: Some text here

      

Now the log file is displayed in real time and it would be nice to make the lines with the same section number in the same color. However, there could be a potentially quite large range of numbers.

What I want to do is create a method that will take a number and randomly generate a unique color. The color should be readable on a black background, so # 000000 is not appropriate, nor is # 101010 or anything too dark to read.

Ideally, two numbers that are the same will not have the same color, because in the examples above, the numbers 1 and 17 may be too similar, and some numbers may be in the 10,000 range.

Any ideas on this?

+2


a source to share


2 answers


Yes. Just generate random numbers for the HSV color space and make sure the V is higher than 50% (so it's not that dark). Convert back to RGB as needed . Pretty simple.



To make sure the colors aren't too similar ... I don't know. Figure out the range of possible numbers and divide the color wheel evenly?

+1


a source


There are some fairly strict cognitive limits on the number of different colors you can use. It would be best to choose the range of colors carefully. If you really need to differentiate between more than a dozen or so individual elements, you will need to use something else, such as changing the background color.

Also, remember that 10% of men (and therefore developers) are color blind, so unless it's for your own benefit, I won't rely too much on color.



A very interesting alternative method can be found in the TortoiseSVN hover tool, which dynamically allocates lines with appropriate changes as the mouse moves over the window.

+2


a source







All Articles