This is an upgrade of the same idea expressed in pg's decorated string, with a couple of improvements: The code is taken from pg's version, so you'll notice some obvious similarities.

use strict; use warnings; my $text =<<"__TEXT__"; This is a sample text going from red to blue, from 10 to 20 points in +size and with 5 points random variation. __TEXT__ print decorate( $text, [255,0,0], [0,0,255], 10, 20, 5); sub decorate { my ($str, $cl, $cr, $szl, $szr, $randomsize) = @_; my $s; my $lenStr = length( $str ); for ( my $i = 0; $i < $lenStr; $i++) { my $c = substr($str, $i, 1); if ($c eq ' ') { $s .= "&nbsp;\n"; } else { my $red = interpolate( $cl->[0], $cr->[0], $lenStr, $i, 0 +); my $grn = interpolate( $cl->[1], $cr->[1], $lenStr, $i, 0 +); my $blu = interpolate( $cl->[2], $cr->[2], $lenStr, $i, 0 +); my $siz = interpolate( $szl, $szr, $lenStr, $i, $rando +msize ); $s .= sprintf("<span style=\"font-size: %dpt; color: #%02x +%02x%02x\">$c</span>", $siz, $red, $grn, $blu, $c); } } return $s; } sub interpolate { my ($from, $to, $nSteps, $thisStep, $randomShift) = @_; my $realStep = $thisStep - $randomShift + rand($randomShift*2); my $val = $from + (($to-$from)/$nSteps) * $realStep; if ( $val < min($from,$to) ) { $val = min($from, $to) }; if ( $val > max($from,$to) ) { $val = max($from, $to) }; return $val; } sub min() { my ($a, $b) = @_; return ($a < $b) ? $a : $b; } sub max() { my ($a, $b) = @_; return ($a > $b) ? $a : $b; }

In reply to Decorated string, v1.1 by l3nz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.