| Acme-Tango documentation | Contained in the Acme-Tango distribution. |
Acme::Tango - Turn colours orange
version 0.07
use Acme::Tango;
my $hex_string = Acme::Tango::drink('#00bbff');
# But then also
my $hex_string = Acme::Tango::drink('#00bbcc', 'apple');
Given a hex rgb colour string (like: "#aaff4f" or "44f567" or "#fab"),
returns the hex string of the shade of orange with the same saturation
and value values. Unless you specifically specify that Apple or Lemon
tango are what you're after, by passing apple or lemon as the
second argument. See:
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:
Pete Sergeant - pete@clueball.com
http://www.tango.com
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
| Acme-Tango documentation | Contained in the Acme-Tango distribution. |
#!perl package Acme::Tango; BEGIN { $Acme::Tango::VERSION = '0.07'; } use strict; use warnings; use Carp qw(croak); use Convert::Color; use Convert::Color::RGB8; use Convert::Color::HSV; 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;