X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/a4fdefae72afac5a4ad02eabcc23fe762903ad89..278de4c46a99f7ebc9fdbf8354283cdef6a31c88:/termcol.plp
diff --git a/termcol.plp b/termcol.plp
index fd2bc9b..04b6e6e 100644
--- a/termcol.plp
+++ b/termcol.plp
@@ -32,7 +32,7 @@ use Shiar_Sheet::Colour '1.03';
use List::Util qw( min max );
sub colcell {
- my $name = shift or return "
\n";
+ my $name = shift // return " | \n";
my $col = Shiar_Sheet::Colour->new(@_);
my $minhex = $col->rgb24;
my $css = '#' . $col->rgb48;
@@ -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,47 +250,66 @@ 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}) {
$out .= '';
$out .= colcell(@$_) for map { $_->[$h] } map { @{$_} } @colmap;
}
- $out .= " \n\n";
$offset += $dim ** 3;
$greymap{$offset++} = $_ for @{$greyramp};
- $out .= ' ';
+ $out .= '';
my $col = 0;
- my $colbreak = keys(%greymap) / 2; # split into 2 rows
+ my $colbreak = scalar map { @$_ } @colmap; # same width as hue rows
for my $num (sort { $greymap{$a} <=> $greymap{$b} } keys %greymap) {
$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";
+}
:>
-<: } :>
|