Sometime you see people use colorful screen names in chat rooms, and this piece of code can be used to decorate your screen name or other strings. Here are some samples:

This string is decorated
This string is decorated
use strict; use warnings; print decorate("This string is decorated", [255,125,125], [255,255,0], + 2); print "<br>"; print decorate("This string is decorated", [125,0,255], [0,255,0], 2); + print "<br>"; sub decorate { my ($str, $left, $right, $size) = @_; my @step; $step[$_] = ($right->[$_] - $left->[$_]) / (length($str) - 1) for +(0 .. 2); my @chars = split //, $str; foreach (0 .. $#chars) { $chars[$_] = sprintf("<font size=%d color=#%02x%02x%02x>$chars +[$_]</font>", $size, $left->[0] + $_ * $step[0], $left->[1] + $_ * $s +tep[1], $left->[2] + $_ * $step[2]); } return join("", @chars); }

Replies are listed 'Best First'.
Re: decorated string
by cleverett (Friar) on Nov 17, 2003 at 06:00 UTC

      You are obviously right, and many thanks for your comment;-) Yes, data is one thing, and how data get rendered is a totally seperated thing. This is why we have CSS, this is why people try to push XHTML, and this is why XML is a more reasonable way to describe data.

      However in a chat room, you don't really control the style of a entire web page. Your sentences are simply small pieces of a long dialog being rendered as a web page. In this context, font is probably the easiest doable way.

      But in general, I agree with you.

        What keeps you from changing the font tag to <span style="..."> ?

        Makeshifts last the longest.

        It really depends on the DOCTYPE string that is set in your HTML pages. If your DOCTYPE is set to a version of HTML before 4 then you are ok. Versions of HTML after 3.2 deprecated the font tag (and a few other tags). And if you are using XHTML forget it. Any font tag is invalid in XHTML. In XHTML CSS is the only way to go.

        Here are lists of elements deprecated in html 4 and in xhtml.

        If you are not using a DOCTYPE then all bets are off. Its a crapshoot on how browsers will render your page.