App-ColorNamer
view release on metacpan or search on metacpan
lib/App/ColorNamer.pm view on Meta::CPAN
$color->{exact} = 1;
last;
}
my $ndf1 = ($color->{rgb}{r} - $try_col->{rgb}{r})**2
+ ($color->{rgb}{g} - $try_col->{rgb}{g})**2
+ ($color->{rgb}{b} - $try_col->{rgb}{b})**2;
my $ndf2 = ($color->{hsl}{h} - $try_col->{hsl}{h})**2
+ ($color->{hsl}{s} - $try_col->{hsl}{s})**2
+ ($color->{hsl}{l} - $try_col->{hsl}{l})**2;
my $ndf = $ndf1 + $ndf2 * 2;
if ( $df < 0 or $df > $ndf ) {
$df = $ndf;
$cl = $_;
}
}
if ( $cl < 0 ) {
$self->error("Color did not match anything");
return;
}
@$color{ qw/hex name rgb hsl/ }
= @{ $colors->[$cl] }{ qw/hex name rgb hsl/ };
return $self->color( $color );
}
sub _make_proper_code {
my $self = shift;
my $code = shift;
$code =~ s/[^[:xdigit:]]+//g;
unless ( length($code) == 3 or length($code) == 6 ) {
$self->error("Color code must be either three or six hex digits");
return;
}
$code =~ s/(.)/$1$1/g
if length($code) == 3;
return lc $code;
}
sub _filter_weird_colors {
my $self = shift;
my $colors = shift;
my %good_colors = map +( lc $_ => 1 ), @{ $self->sane_colors };
return [ grep $good_colors{ $_->{hex} }, @$colors ];
}
sub _get_sane_colors {
return [qw/
000000 000080 0000C8 0000FF 008080 00FF00 00FFFF 0C0B1D 130A06
1560BD 161D10 240A40 242E16 251607 262335 30D5C8 315BA1 370202
3C2005 3C4151 3F2109 3F2500 4169E1 41AA78 4F69C6 50C878 5F5F6E
6456B7 660099 661010 66FF00 6B8E23 6CDAE7 6E7783 76D7EA 7A58C1
808000 808080 8B8680 964B00 9AC2B8 A8989B A9A491 A9ACB6 ABA0D9
ADDFAD ADFF2F B10000 B57EDC B5B35C B7410E B87333 BDBBD7 BFFF00
C0C0C0 C5E17A C62D42 C71585 CC5500 D2B48C D7D0FF E0B0FF E0FFFF
F5F5DC F7468A FDE910 FEFCED FF0000 FF00FF FF3F34 FF681F FF69B4
FFBF00 FFC0CB FFD700 FFD800 FFE5B4 FFFF00 FFFFF0 FFFFFF
/];
}
sub _get_colors {
return [
['000000', 'Black'],
['000080', 'Navy Blue'],
['0000C8', 'Dark Blue'],
['0000FF', 'Blue'],
['000741', 'Stratos'],
['001B1C', 'Swamp'],
['002387', 'Resolution Blue'],
['002900', 'Deep Fir'],
['002E20', 'Burnham'],
['002FA7', 'International Klein Blue'],
['003153', 'Prussian Blue'],
['003366', 'Midnight Blue'],
['003399', 'Smalt'],
['003532', 'Deep Teal'],
['003E40', 'Cyprus'],
['004620', 'Kaitoke Green'],
['0047AB', 'Cobalt'],
['004816', 'Crusoe'],
['004950', 'Sherpa Blue'],
['0056A7', 'Endeavour'],
['00581A', 'Camarone'],
['0066CC', 'Science Blue'],
['0066FF', 'Blue Ribbon'],
['00755E', 'Tropical Rain Forest'],
['0076A3', 'Allports'],
['007BA7', 'Deep Cerulean'],
['007EC7', 'Lochmara'],
['007FFF', 'Azure Radiance'],
['008080', 'Teal'],
['0095B6', 'Bondi Blue'],
['009DC4', 'Pacific Blue'],
['00A693', 'Persian Green'],
['00A86B', 'Jade'],
['00CC99', 'Caribbean Green'],
['00CCCC', 'Robin\'s Egg Blue'],
['00FF00', 'Green'],
['00FF7F', 'Spring Green'],
['00FFFF', 'Cyan / Aqua'],
['010D1A', 'Blue Charcoal'],
['011635', 'Midnight'],
['011D13', 'Holly'],
['012731', 'Daintree'],
['01361C', 'Cardin Green'],
['01371A', 'County Green'],
['013E62', 'Astronaut Blue'],
['013F6A', 'Regal Blue'],
['014B43', 'Aqua Deep'],
['015E85', 'Orient'],
( run in 2.798 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )