X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/c37471e7de29ef22e46af32074478bd86a48a0b1..032b7eb4897d7517e94c7fe2e1d414be8d925c9f:/termcol.plp
diff --git a/termcol.plp b/termcol.plp
index d945079..9262bf3 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,36 +226,11 @@ for my $term (@termlist) {
- 88-colour space
-<:
-for my $r (0 .. 3) {
- print ' ';
- for my $g (0 .. 3) {
- print '';
- for my $b (0 .. 3) {
- my $index = $r*4*4 + $g*4 + $b + 16;
- print colcell($index, map {(0, 139, 205, 255)[$_]} $r, $g, $b);
- }
- }
- print " \n";
-}
-print "\n";
-
-print ' ';
-print colcell(80+$_, (($_ + 2 + ($_>0)) * 255/11) x 3) for 0 .. 7;
-print "
\n\n";
-
-:>
-<: if ($ENV{PATH_INFO} =~ /256/) { :>
-
-
-
- 256-colour space
<:
sub coltable_hsv {
my ($dim, $rgbval, $greyramp) = @_;
- my $hmax = ($dim + $dim - 1) * 2 + ($dim - 2) * 2 + 3;
+ my $hmax = 2 * $dim * 3; # each face of the rgb cube
my $vmax = $dim - 1;
my $smax = $dim - 1;
@@ -267,21 +242,21 @@ sub coltable_hsv {
for my $g (0 .. $dim - 1) {
for my $b (0 .. $dim - 1) {
my $index = $r*$dim*$dim + $g*$dim + $b + $offset;
- my @rgb = map { &$rgbval } $r, $g, $b;
+ my @rgb = ($r, $g, $b);
my $h = Shiar_Sheet::Colour->new(@rgb)->hue * $hmax;
- my $v = int(max(@rgb) / 255 * $vmax);
- my $s = abs(min(@rgb) - max(@rgb)) / 255 * $smax;
+ my $v = max(@rgb);
+ my $s = abs(min(@rgb) - max(@rgb));
if (!$s) {
- $greymap{$index} = $rgb[0];
+ $greymap{$index} = $rgbval->($r);
next;
}
$v = $vmax - $v;
$s = $smax - $s - $v;
- $colmap[$s][$v][$h] = [$index, @rgb];
+ $colmap[$s][$v][$h] = [$index, map { $rgbval->($_) } @rgb];
}
}
}
@@ -293,14 +268,13 @@ sub coltable_hsv {
$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);
@@ -310,11 +284,21 @@ sub coltable_hsv {
return $out;
}
-print coltable_hsv(6,
- sub { $_ && $_*40 + 55 },
- [ map { $_ * 10 + 8 } 0 .. 23 ],
-);
+{
+ print "88-colour space\n";
+ print coltable_hsv(4,
+ sub {(0, 139, 205, 255)[$_[0]]},
+ [map { ($_ + 2 + ($_>0)) * 255/11 } 0 .. 7],
+ );
+}
+
+if ($ENV{PATH_INFO} =~ /256/) {
+ print "256-colour space\n";
+ print coltable_hsv(6,
+ sub { $_[0] && $_[0]*40 + 55 },
+ [ map { $_ * 10 + 8 } 0 .. 23 ],
+ );
+}
:>
-<: } :>
|