- print colcell($index, map { $_ && $_*40 + 55 } $r, $g, $b);
+ my @rgb = map { $_ && $_*40 + 55 } $r, $g, $b;
+
+ my $h = Shiar_Sheet::Colour->new(@rgb)->hue * 35;
+ my $v = int(max(@rgb) / 255 * 5);
+ my $s = abs(min(@rgb) - max(@rgb)) / 255 * 7;
+ my $grey = !$s;
+
+ $h-- for grep {$h >= $_} 4, 6, 16, 19, 28, 31;
+ $v = 5 - $v;
+ $s = 7 - $s - $v;
+ $s-- if $s;
+
+ if ($grey) {
+ $h = 30; # greyscale hue
+ $s -= 2; # lowest saturation for other hues
+ $v = $s = 0 if $s < 0; # black at full saturation
+ }
+
+ $colmap[$s][$v][$h] = [$index, @rgb];