From d29916edd5f2af73164483662b5e49fdc6e3e697 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 31 Oct 2015 21:14:44 +0100 Subject: [PATCH] termcol: list 256-colour hues starting with red MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Most wheels have red at 0° so having it on top is more familiar. Coincidentally also avoids undesirable row breaks. --- Shiar_Sheet/Colour.pm | 7 +++++-- termcol.plp | 9 ++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Shiar_Sheet/Colour.pm b/Shiar_Sheet/Colour.pm index cedfdfb..cdac0b3 100644 --- a/Shiar_Sheet/Colour.pm +++ b/Shiar_Sheet/Colour.pm @@ -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 { diff --git a/termcol.plp b/termcol.plp index 74bcbc4..5a4e83e 100644 --- a/termcol.plp +++ b/termcol.plp @@ -28,7 +28,7 @@ print
<: -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 ''; printf '', 3 * @{$_} for @colmap; - for my $h (0 .. 30) { + for my $h (grep { $colmap[0][0][$_] } 0 .. $#{ $colmap[0][0] }) { print ''; print colcell(@$_) for map { $_->[$h] } map { @{$_} } @colmap; } -- 2.30.0