Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: to generate a set of well contrasted colors

by pg (Canon)
on Nov 07, 2003 at 02:45 UTC ( [id://305220]=note: print w/replies, xml ) Need Help??


in reply to Re: to generate a set of well contrasted colors
in thread to generate a set of well contrasted colors

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:

pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead
pg blokhead

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-23 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found