#!/usr/bin/perl
# Perl Color Blend Demo
# by Anatoli Radulov
use warnings;
use strict;
print "Content-type: text/html\n\n
";
#blend demo 1
print "";
&blender ("#000000","#FFFFFF",12);
&blender ("#ff0000","#FFFFFF",12);
&blender ("#00ff00","#FFFFFF",12);
&blender ("#0000ff","#FFFFFF",12);
print "
\n";
#blend demo 2
print "";
&blender ("#FF0000","#FFFF00",20);
&blender ("#FFFF00","#00FFFF",20);
&blender ("#00FFFF","#FF00FF",20);
&blender ("#FF00FF","#FF0000",20);
print "
";
print "";
###################################################################################################
sub blender {
my (@range, @color1, @color2);
#hex2dec;
@color1 = ( @_[0] =~ /#([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/ );
@color2 = ( @_[1] =~ /#([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/ );
$_ = hex($_) foreach @color1;
$_ = hex($_) foreach @color2;
#calculate blend ranges
$range[$_] = ($color2[$_] - $color1[$_])/@_[2] for (0..2);
#blend @_[2] steps
for (0..@_[2]) {
print " | \n";
}
}