in reply to Generating Visually Distinct Colors
japhy, you might find Coloring IRC logs nicely interesting, too.
This is the algorithm my IRC bot iblechbot uses, too (screenshot).
First, a raw IRC log is read to find out which nicks were online (and talked) at the same time. This information is used to build a interference graph. Then, using the graph, all nicks get distict colors.
Because of the interference graph, the colors used are reduced to a minimum:
Using the colornum/total_num_of_colors information, the actual color pair (foreground, background) is built:
sub calc_color { my ($i, $ncolors) = @_; $ncolors = 1 if $ncolors == 0; # No division /0. my $a = 0.95; # tune these for the starting and ending concentra +tions of R,G,B my $b = 0.5; my $rgb = [ [$a,$b,$b], [$b,$a,$b], [$b,$b,$a], [$a,$a,$b], [$a,$b,$ +a], [$b,$a,$a] ]; my $rgbmax = 125; # tune these two for the outmost ranges of colou +r depth my $rgbmin = 240; my $n = $i % @$rgb; my $m = $rgbmin + ($rgbmax - $rgbmin) * ($ncolors - $i) / $ncolors; my @c = map { $rgb->[$n][$_] * $m } 0 .. 2; my $g = $c[0] * .3 + $c[1] * .59 + $c[2] * .11; my $f = $g > 127 ? "#000000" : "#ffffff"; my $h = sprintf "#%02x%02x%02x", @c; ($f, $h); }
|
|---|