Created
September 3, 2009 16:06
-
-
Save EvanCarroll/180373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
package AleenaCode; | |
use warnings; | |
use strict; | |
use Sub::Exporter -setup => { exports => [qw/ | |
random_color HTML_color random_color_with_key | |
get_totally_random_color | |
/] }; | |
#HTML color | |
my @brightness = qw(white pale light medium dark obscure black); | |
my @vividness = qw(vivid hard faded dull weak gray); | |
my @hue = qw(red orange yellow spring green teal cyan azure blue violet magenta pink); | |
my %colors = ( | |
additive_primary_colors => [qw(red green blue)] | |
, additive_secondary_colors => [qw(yellow cyan magenta)] | |
, subtractive_primary_colors => [qw(red yellow blue)] | |
, subtractive_secondary_colors => [qw(orange green violet)] | |
, pure_colors => [qw(red yellow green blue)] | |
, rainbow_colors => [qw(red orange yellow green blue indigo violet)] | |
, spectral_colors => [qw(infrared red orange yellow green blue violet ultraviolet)] | |
); | |
sub random_color { | |
my $name = shift; | |
my $name_colors = $colors{$name}; | |
return $name_colors->[rand(@$name_colors)] | |
} | |
sub HTML_color { | |
my $brightness = $brightness[rand(@brightness)]; | |
my $vividness = $vividness[rand(@vividness)]; | |
my $hue = $hue[rand(@hue)]; | |
return "$brightness" | |
if $brightness eq "white" || $brightness eq "black" | |
; | |
return "$brightness $vividness" | |
if $vividness eq "gray" | |
; | |
"$brightness $vividness $hue"; | |
} | |
sub random_color_with_key { | |
my $name = shift; | |
my $name_colors = $colors{$name}; | |
$name =~ tr/_/ /; | |
return ucfirst $name." = ".$name_colors->[rand(@$name_colors)]."\n"; | |
} | |
sub get_totally_random_color { | |
my @color_key = keys(%colors); | |
my $random_color_key = rand(@color_key); | |
print random_color_with_key($color_key[$random_color_key]); | |
} | |
package main; | |
use warnings; | |
use strict; | |
use diagnostics; | |
AleenaCode->import( ':all' ); | |
print "HTML color 1 = ".HTML_color()."\n"; | |
print "HTML color 2 = ".HTML_color()."\n"; | |
print "\n"; | |
print random_color_with_key("additive_primary_colors"); | |
print random_color_with_key("additive_secondary_colors"); | |
print random_color_with_key("subtractive_primary_colors"); | |
print random_color_with_key("subtractive_secondary_colors"); | |
print random_color_with_key("pure_colors"); | |
print random_color_with_key("rainbow_colors"); | |
print random_color_with_key("spectral_colors"); | |
print "Really random color - "; | |
get_totally_random_color(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment