"be consistent" PerlMonks

### Re: Ordering Colours Problem

by choroba (Archbishop)
 on Mar 05, 2021 at 12:47 UTC Need Help??

in reply to Ordering Colours Problem

Based on Math behind Colourspace Conversions, I was able to at least sort the colours:
```#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };

sub hue {
my (\$colour) = @_;
my %rgb;
@rgb{qw{ red green blue }} = map hex(\$_) / 255, \$colour =~ /^#(..)
+(..)(..)/;
my @order = sort { \$rgb{\$a} <=> \$rgb{\$b} } keys %rgb;
my \$hue = {red   => sub { 0 + \$rgb{green} - \$rgb{blue}},
green => sub { 2 + \$rgb{blue}  - \$rgb{red} },
blue  => sub { 4 + \$rgb{red}   - \$rgb{green} }
}->{ \$order[2] }->();
my \$d = \$rgb{ \$order[2] } - \$rgb{ \$order[0]};
return 0 if 0 == \$d;

\$hue /= \$d;
\$hue *= 60;
\$hue += 360 if \$hue < 0;
return \$hue
}

my @colours = do { no warnings 'qw';
qw( #000000 #716373 #704A2B #AF7E45 #963049 #AA2261
#B24551 #E6212E #FF0000 #001200 #FFDE72 #F55B73
+ ) };
my %hue = map { \$_ => hue(\$_) } @colours;
my @sorted = sort { \$hue{\$a} <=> \$hue{\$b} } keys %hue;
say "@sorted";
The black/white problem is not solved here, so feel free to expand as you need.
map{substr\$_->[0],\$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Create A New User
Node Status?
node history
Node Type: note [id://11129158]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-04-15 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?