sub BlackBody {
ColormapHtml( BlackBodyMap() );
ColormapHtml( GreyscaleMap() );
}
sub ColormapHtml {
my $blackbody = shift;
print "
";
while(@$blackbody){
print "";
#~ for(1..8){
#~ for(1..16){
for(1..32){
my $color = shift @$blackbody;
#~ my $hex = join '', map { pack 'H*', $_ } @$color;
my $hex = rgb2hex( @$color );
#~ print qq[| $hex | ];
print qq[_ | ];
}
print "
";
}
print "
";
}
sub rgb2hex {
#~ my( $r, $g, $b ) = @_;
sprintf '%02x%02x%02x', @_;
}
sub BlackBodyMap {
my $one = [ 255, 0, 0 ] ;
my $two = [ 255, 255, 0 ];
my @colormap = (
YuckFoo( 85, [0,0,0] => $one ),
YuckFoo( 85, $one => $two ),
YuckFoo( 86, $two => [255,255,255] ),
);
return \@colormap;
}
sub GreyscaleMap {
return [ YuckFoo(256, [0,0,0] => [255,255,255] ) ];
}
sub YuckFoo {
my( $steps, $beg, $end) = @_;
# RGB rate of change from beginning to ending color
my @delta = (
($$end[0] - $$beg[0]) / ($steps-1),
($$end[1] - $$beg[1]) / ($steps-1),
($$end[2] - $$beg[2]) / ($steps-1),
);
# Calculate colors using beginning color and rate of change
my $i = 0;
my @gradient;
while($i < $steps) {
my $color = [
$$beg[0] + $i * $delta[0],
$$beg[1] + $i * $delta[1],
$$beg[2] + $i * $delta[2]
];
push @gradient, $color;
$i++;
}
return @gradient;
}