termcol: list 256-colour hues starting with red
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 31 Oct 2015 20:14:44 +0000 (21:14 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 31 Oct 2015 21:02:06 +0000 (22:02 +0100)
Most wheels have red at 0° so having it on top is more familiar.
Coincidentally also avoids undesirable row breaks.

Shiar_Sheet/Colour.pm
termcol.plp

index cedfdfb9e31aa722ff8027657fba1b97c455fb26..cdac0b346066b204e70fa148001c959ab74de43b 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use List::Util qw( min max );
 
-our $VERSION = '1.02';
+our $VERSION = '1.03';
 
 # ITU-R recommendation 601 luma co-efficients
 our $kr = .299;
@@ -42,9 +42,12 @@ sub luminance {
 }
 
 sub hue {
+       # colour shift (red = 0 .. 1)
        my ($r, $g, $b) = @{ $_[0] };
        my $hue = atan2 sqrt(3) * ($g - $b), $r*2 - $g - $b;
-       return ($hue + $PI) / $PI / 2; # 0 .. 1
+       $hue /= $PI * 2;  # -.5 .. .5
+       $hue++ if $hue < 0;  # fp $hue %= 1
+       return $hue;
 }
 
 sub rgb24 {
index 74bcbc4ae7f7fde7044bdc5f5a9f927e2b2c88b3..5a4e83eed9b4b285bdfdb2edcdd55f3fad308da0 100644 (file)
@@ -28,7 +28,7 @@ print
 
 <div class="section">
 <:
-use Shiar_Sheet::Colour '1.02';
+use Shiar_Sheet::Colour '1.03';
 use List::Util qw( min max );
 
 sub colcell {
@@ -259,18 +259,17 @@ for my $r (0 .. 5) {
                        my $index = $r*6*6 + $g*6 + $b + 16;
                        my @rgb = map { $_ && $_*40 + 55 } $r, $g, $b;
 
-                       my $h = Shiar_Sheet::Colour->new(@rgb)->hue * 35;
+                       my $h = Shiar_Sheet::Colour->new(@rgb)->hue * 33;
                        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
+                               $h = 33;  # greyscale hue
                                $s -= 2;  # lowest saturation for other hues
                                $v = $s = 0 if $s < 0;  # black at full saturation
                        }
@@ -283,7 +282,7 @@ for my $r (0 .. 5) {
 {
        print '<table class=mapped>';
        printf '<colgroup span=%d>', 3 * @{$_} for @colmap;
-       for my $h (0 .. 30) {
+       for my $h (grep { $colmap[0][0][$_] } 0 .. $#{ $colmap[0][0] }) {
                print '<tr>';
                print colcell(@$_) for map { $_->[$h] } map { @{$_} } @colmap;
        }