termcol: list 256-colour hues starting with red
[sheet.git] / Shiar_Sheet / Colour.pm
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 {