-<p class="footer">
- <a href="/" rel="home">sheet.shiar.nl</a>/termcol.<a href="/source/termcol.plp"
- rel="code" title="Written in Perl">plp</a>
- <a href="http://git.shiar.nl/sheet.git/history/HEAD:/termcol.plp"
- rel="vcs-git" title="Git repository"><:= $VERSION :></a>
- created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
- <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="copyright"
- title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
-</p>
+ my $hmax = 2 * $dim * 3; # each face of the rgb cube
+ my $vmax = $dim - 1;
+ my $smax = $dim - 1;
+ $rgbval ||= sub { join('', @_), map { int $_ * 255 / $vmax } @_ };
+
+ my @greymap = @{$greyramp || []}; # [name, r, g=l, b]
+ my @colmap; # saturation => value => hue => [name, r,g,b]
+
+ for my $r (0 .. $dim - 1) {
+ for my $g (0 .. $dim - 1) {
+ for my $b (0 .. $dim - 1) {
+ my @rgb = ($r, $g, $b);
+
+ my ($h, $s, $v) = Shiar_Sheet::Colour->new(@rgb)->hsv;
+
+ if (!$s) {
+ if (@greymap) {
+ push @greymap, [ $rgbval->(@rgb) ];
+ next;
+ }
+
+ $h = 1; # greyscale hue
+ $s = $smax - $v + 1; # spread brightness over saturation groups
+ $v &&= $smax # highest saturation
+ or $v = $s = 1; # black at initial column
+ }
+
+ $h *= $hmax;
+ $v = $vmax - $v;
+ $s = $smax - $s - $v;
+
+ $colmap[$s][$v][$h] = [ $rgbval->(@rgb) ];
+ }
+ }
+ }
+
+ my $out = '';
+ $out .= sprintf '<colgroup span=%d>', scalar @{$_} for @colmap;
+ my $huerow = $colmap[0][0]; # first {$_} map { @{$_} } @colmap;
+ for my $h (grep { $huerow->[$_] } 0 .. $#{$huerow}) {
+ $out .= '<tr>';
+ $out .= colcell(@$_) for map { $_->[$h] } map { reverse @{$_} } @colmap;
+ }
+
+ if (@greymap) {
+ $out .= '<tbody>';
+ my $col = 0;
+ my $colbreak = scalar map { @$_ } @colmap; # same width as hue rows
+ for my $cell (sort { $a->[1] <=> $b->[1] || $a->[0] <=> $b->[0] } @greymap) {
+ $out .= '<tr>' unless $col++ % $colbreak;
+ $out .= colcell(@{$cell});
+ }
+ }
+
+ if (@draw) {
+ my @palette = map { [ @{$_}[1 .. 3] ] } @greymap, map {@$_} map {@$_} @colmap;
+ my $tablespan = scalar map { @$_ } @colmap;
+ my $imgdata = img_egapal(\@palette, @{ $draw[0] });
+ $out .= "<tr><td colspan=$tablespan>$imgdata";
+ }
+
+ return $out;
+}
+
+coltable($_) for @termlist;
+:></div>
+<hr>