Acme-Tango

 view release on metacpan or  search on metacpan

lib/Acme/Tango.pm  view on Meta::CPAN

our %flavours = (
	apple        => 105,
	blackcurrant => 300,
	cherry       => 0,
	lemon        => 60,
	orange       => 40
);

sub drink {
	my ( $hex, $flavour ) = @_;
	$flavour ||= 'orange';

	# Pick the transformation hue
	my $new_hue = $flavours{$flavour};
	croak "Unknown flavour [$flavour]" unless defined $new_hue;

	# Sanity-check the incoming colour
	my $prefix = $hex =~ s/^#// ? '#' : '';
	croak "Please provide a valid hex colour"
		unless $hex =~ m/^([0-9a-f]{3}|[0-9a-f]{6})$/i;
	$hex =~ s/(.)/$1$1/g if length($hex) == 3;

	# Convert to HSV
	my ( $old_hue, $s, $v ) = Convert::Color::RGB8->new( $hex )->as_hsv->hsv;

	# Back to RGB
	my $new_color = Convert::Color::HSV->new( $new_hue, $s, $v )->as_rgb8->hex;

	# Back to the user!
	return uc($prefix . $new_color);
}

1;

=head1 NAME

Acme::Tango - Turn colours orange

=head1 VERSION

version 0.07

=head1 SYNOPSIS

	use Acme::Tango;

	my $hex_string = Acme::Tango::drink('#00bbff');

 # But then also

  my $hex_string = Acme::Tango::drink('#00bbcc', 'apple');

=head1 METHODS

=head2 drink

Given a hex rgb colour string (like: "#aaff4f" or "44f567" or "#fab"),
returns the hex string of the shade of orange with the same I<saturation>
and I<value> values. Unless you specifically specify that Apple or Lemon
tango are what you're after, by passing C<apple> or C<lemon> as the
second argument. See:

L<https://rt.cpan.org/Ticket/Display.html?id=6730>

=head1 EXAMPLE

C<perl eg/colour_swatches.pl> should give you an HTML segment to look
at. If you're reading this page in an HTML-compatible POD reader, you
can see the results below:

=begin html

<table bgcolor = '#000000'><tr>
<td><h3><font color = '#ffffff'>Orange</font></h3><table>
<tr><td bgcolor = "#000000">000000</td><td bgcolor = "#000000">000000</td></tr><tr><td bgcolor = "#000033">000033</td><td bgcolor = "#332200">332200</td></tr><tr><td bgcolor = "#000066">000066</td><td bgcolor = "#664400">664400</td></tr><tr><td bgcol...
<td><h3><font color = '#ffffff'>Lemon</font></h3><table>
<tr><td bgcolor = "#000000">000000</td><td bgcolor = "#000000">000000</td></tr><tr><td bgcolor = "#000033">000033</td><td bgcolor = "#333300">333300</td></tr><tr><td bgcolor = "#000066">000066</td><td bgcolor = "#666600">666600</td></tr><tr><td bgcol...
<td><h3><font color = '#ffffff'>Apple</font></h3><table>
<tr><td bgcolor = "#000000">000000</td><td bgcolor = "#000000">000000</td></tr><tr><td bgcolor = "#000033">000033</td><td bgcolor = "#0C3300">0C3300</td></tr><tr><td bgcolor = "#000066">000066</td><td bgcolor = "#196600">196600</td></tr><tr><td bgcol...
<td><h3><font color = '#ffffff'>Blackcurrant</font></h3><table>
<tr><td bgcolor = "#000000">000000</td><td bgcolor = "#000000">000000</td></tr><tr><td bgcolor = "#000033">000033</td><td bgcolor = "#330033">330033</td></tr><tr><td bgcolor = "#000066">000066</td><td bgcolor = "#660066">660066</td></tr><tr><td bgcol...
<td><h3><font color = '#ffffff'>Cherry</font></h3><table>
<tr><td bgcolor = "#000000">000000</td><td bgcolor = "#000000">000000</td></tr><tr><td bgcolor = "#000033">000033</td><td bgcolor = "#330000">330000</td></tr><tr><td bgcolor = "#000066">000066</td><td bgcolor = "#660000">660000</td></tr><tr><td bgcol...
</tr></table>

=end html

=head1 AUTHOR

Pete Sergeant - pete@clueball.com

=head1 SEE ALSO

http://www.tango.com

=head1 LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.

Tango is someone else's registered trademark - see: http://www.tango.com

=cut



( run in 2.035 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )