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

In reply to Re: A hierarchy of color (intensity)? by inman
in thread A hierarchy of color (intensity)? by BrowserUk

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.