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 concentrations 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 colour 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); }