#!/usr/bin/perl
use strict;
# PUBLIC DOMAIN 2016 Julie Kirsty Louise Montoya
my ($from_hex, $from_red, $from_green, $from_blue,
$to_hex, $to_red, $to_green, $to_blue,
$step, $steps, $hex, $red, $green, $blue,
$text, $sep, $letter);
$from_hex = shift;
die "Bad 'from' colour" unless $from_hex =~ /^[0-9a-fA-F]{6}$/;
$to_hex = shift;
die "Bad 'to' colour" unless $to_hex =~ /^[0-9a-fA-F]{6}$/;
$text = $sep = "";
while (@ARGV) {
$text .= $sep . shift;
$sep = " ";
};
$from_hex =~ /([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/;
$from_red = hex $1;
$from_green = hex $2;
$from_blue = hex $3;
$to_hex =~ /([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/;
$to_red = hex $1;
$to_green = hex $2;
$to_blue = hex $3;
print "\n";
$steps = length $text;
for ($step = 0; $step < $steps; ++$step) {
$red = $from_red + ($to_red - $from_red) * $step / ($steps - 1);
$green = $from_green + ($to_green - $from_green) * $step / ($steps - 1);
$blue = $from_blue + ($to_blue - $from_blue) * $step / ($steps - 1);
$letter = substr $text, $step, 1;
if ($letter eq " ") {
print " ";
}
else {
printf "[color=#%02x%02x%02x]%1s[/color]", $red, $green, $blue, $letter;
};
};
print "\n";
exit;