Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: A hierarchy of color (intensity)?

by inman (Curate)
on Nov 22, 2005 at 10:01 UTC ( [id://510700]=note: print w/replies, xml ) Need Help??


in reply to A hierarchy of color (intensity)?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://510700]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found