X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/13c7c8e9c8f8b5c583ca5563161e177b1a133e5e..278de4c46a99f7ebc9fdbf8354283cdef6a31c88:/termcol.plp
diff --git a/termcol.plp b/termcol.plp
index 189b89c..04b6e6e 100644
--- a/termcol.plp
+++ b/termcol.plp
@@ -226,19 +226,6 @@ for my $term (@termlist) {
-
88-colour space
-<:
-print coltable_hsv(4,
- sub {(0, 139, 205, 255)[$_[0]]},
- [map { ($_ + 2 + ($_>0)) * 255/11 } 0 .. 7],
-);
-
-:>
-<: if ($ENV{PATH_INFO} =~ /256/) { :>
-
-
-
-
256-colour space
<:
sub coltable_hsv {
my ($dim, $rgbval, $greyramp) = @_;
@@ -246,6 +233,8 @@ sub coltable_hsv {
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 } @_ };
+ $greyramp ||= [];
my %greymap; # name => value
my @colmap; # saturation => value => hue => [name, r,g,b]
@@ -254,7 +243,6 @@ sub coltable_hsv {
for my $r (0 .. $dim - 1) {
for my $g (0 .. $dim - 1) {
for my $b (0 .. $dim - 1) {
- my $index = $r*$dim*$dim + $g*$dim + $b + $offset;
my @rgb = ($r, $g, $b);
my $h = Shiar_Sheet::Colour->new(@rgb)->hue * $hmax;
@@ -262,19 +250,20 @@ sub coltable_hsv {
my $s = abs(min(@rgb) - max(@rgb));
if (!$s) {
- $greymap{$index} = $rgbval->($r);
+ my ($index, $l) = $rgbval->(@rgb);
+ $greymap{$index} = $l;
next;
}
$v = $vmax - $v;
$s = $smax - $s - $v;
- $colmap[$s][$v][$h] = [$index, map { $rgbval->($_) } @rgb];
+ $colmap[$s][$v][$h] = [ $rgbval->(@rgb) ];
}
}
}
- my $out = '
';
+ my $out = '';
$out .= sprintf '', 3 * @{$_} for @colmap;
my $huerow = $colmap[0][0]; # first {$_} map { @{$_} } @colmap;
for my $h (grep { $huerow->[$_] } 0 .. $#{$huerow}) {
@@ -292,16 +281,35 @@ sub coltable_hsv {
$out .= '' unless $col++ % $colbreak;
$out .= colcell($num, ($greymap{$num}) x 3);
}
- $out .= "
\n\n";
return $out;
}
-print coltable_hsv(6,
- sub { $_[0] && $_[0]*40 + 55 },
- [ map { $_ * 10 + 8 } 0 .. 23 ],
-);
+{
+ print "
88-colour space
\n";
+ print "
\n";
+ print coltable_hsv(4,
+ sub {
+ $_[2] + 4 * ($_[1] + 4 * $_[0]) + 16,
+ map { (0, 139, 205, 255)[$_] } @_
+ },
+ [map { ($_ + 2 + ($_>0)) * 255/11 } 0 .. 7],
+ );
+ print "
\n";
+}
+
+if ($ENV{PATH_INFO} =~ /256/) {
+ print "
256-colour space
\n";
+ print "
\n";
+ print coltable_hsv(6,
+ sub {
+ $_[2] + 6 * ($_[1] + 6 * $_[0]) + 16,
+ map { $_ && $_*40 + 55 } @_
+ },
+ [ map { $_ * 10 + 8 } 0 .. 23 ],
+ );
+ print "
\n";
+}
:>
-<: } :>