Quite a few interesting replies came up for this thread!
I come up below piece of code to demon different solutions together. It displays a table that:
- The background color of each row is randomly generated, and keep the same for all cells in the row;
- The foreground color is generated by different solutions, identified by author's name.
To run it, just type:
perl -w blah.pl > result.html
And then use your browser to view result.html.
You will see that each siolution has its merit, and a different look and feel. I think, if you love fish, then take fish; if you love meat, then take meat, all delicious.
sub random_colors {
my ($r, $g, $b) = map { int rand 256 } 1 .. 3;
my $lum = ($r * 0.3) + ($g * 0.59) + ($b * 0.11);
my $bg = sprintf("#%02x%02x%02x", $r, $g, $b);
my $fg1 = sprintf("#%02x%02x%02x", ($r + 128) % 256, ($g + 128) %
+256, ($b + 128) % 256);
my $fg2 = $lum < 128 ? "white" : "black";
return ($bg, $fg1, $fg2);
}
for (1 .. 100) {
my ($bg, $fg1, $fg2) = random_colors();
print qq{
<table>
<tr>
<td bgcolor=$bg><font size=5 color=$fg1>pg</font></td>
<td bgcolor=$bg><font size=5 color=$fg2>blokhead</font></t
+d>
</tr>
</table>
};
}
Here is just a piece of it: