The following code was actually the result of a Perl Monks discussion. The code simply creates an HTML page that contains all the websafe colours. The interesting bit is the luminosity calculation that is used to determine whether the text should be black or white. The colour table produces blocks of 256 colours but this could be extended by increasing the number of starting values.
#! /usr/bin/perl -w
use strict;
use warnings;
my @websafe = qw / 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF /;
print <<EOF;
<html>
<head>
<style>
td {font-size: xx-small;}
</style>
</head>
<body>
<h1>Colour Table</h1>
<table>
EOF
my $bg;
my $lum;
my $fg;
foreach my $red (reverse @websafe)
{
foreach my $green (@websafe)
{
print "<tr>";
foreach my $blue (@websafe)
{
$lum = (hex ($red) * 0.3) + (hex ($green) * 0.59) + (hex($
+blue) * 0.11);
$fg = $lum < 128 ? "#FFFFFF" : "#000000";
print "<td bgcolor= \"#$red$green$blue\"><font color=\"$fg
+\">#$red$green$blue</font></td>";
}
print "</tr>\n";
}
}
print <<EOF;
</table>
</body>
</html>
EOF