Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.

for example: #F0E7FA

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; }

In reply to Re: Creative presentation algorithm: IP to a color by Ven'Tatsu
in thread Creative presentation algorithm: IP to a color by Your Mother

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-28 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found