From a usability stand point I think that you don't want to use the full range of RGB colors. Otherwise you may have a color like #F0E7FA appear on a white page and be nearly invisable.
The easyest way to do that would be to set the most significant bit of each byte of the RGB value to 0 for light backgrounds and 1 for dark backgrounds. This limits the color space to only 21 bits, however setting only one of the most significant bits opposite of the others doesn't move the color too far to make text illegable to me, so picking one or none of the 3 bits gives 4 options, or to look at it another way restores 2 bits to the color space without sacrificing readability of the text.
In my code I do this by using the last 3 bytes of the IP address for the base RGB values, shifting off the least significant bit. Then take the first byte and and xor each 2 bit group with the others to get a 2 bit number to select which byte to set the most significant bit. Finely a flag toggles all the most significant bits if the text should be bright. I think this would effectivly hide the IP address while still keeping many 'close' ip addresses close in color. (though the choice of using the first byte of the IP address to affect the most significant bits by xoring it together will place many distant IP addresses near each other in the color space.)
sub ip2rgb {
my $ip = shift;
my $bright = shift;
my @octets = split /\./, $ip;
my $mso = shift @octets;
my @rgb = map { $_ >> 1 } @octets;
my $msb = ($mso >> 6 & 0x03) ^ ($mso >> 4 & 0x03) ^ ($mso >> 2 & 0
+x03) ^ ($mso >> 2 & 0x03) ^ ($mso & 0x03);
if ($msb != 3) {
$rgb[$msb] |= 0x80;
}
if ($bright) {
for (@rgb) {
$_ ^= 0x80;
}
}
return @rgb;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|