in reply to Creative presentation algorithm: IP to a color

How many IPs do you expect as a max?

Why not choose a list of colors, a suitable hash function for IPs, and use $color{hash(@ip)}?

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Creative presentation algorithm: IP to a color
by eXile (Priest) on Aug 29, 2005 at 02:40 UTC
    MD5 could be used as a hash function here on the IP-string (or any string as a matter of fact), and the first 3 pairs of hex-characters could be used as rgb values:
    #!/usr/bin/perl -l use strict; use Digest::MD5 qw(md5_hex); my $ip="192.168.7.1"; my $ip2="192.168.7.2"; my $ip3="192.168.7.3"; my $ip4="192.168.7.4"; print join(",", ip2color($ip)); print join(",", ip2color($ip2)); print join(",", ip2color($ip3)); print join(",", ip2color($ip4)); sub ip2color { my ($ip) = @_; my $md5 = md5_hex($ip); my @rgb; foreach (0 .. 2) { my $value_in_hex = substr($md5,0+2*$_,2); push @rgb, hex($value_in_hex); } return @rgb; } __DATA__ 251,180,114 35,50,113 80,124,60 221,201,172
    Not meaningful for the eye these colors (like Zaxo's solution), but neighboring IPs very likely will have different colors.
Re^2: Creative presentation algorithm: IP to a color
by Your Mother (Archbishop) on Aug 29, 2005 at 01:59 UTC

    Indeterminate really; visitors' IPs from anywhere. Assume all of them. :) I liked Zaxo's below and I'm going to play with it. Love to see more ideas too. Just for fun.