Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: to generate a set of well contrasted colors

by vacant (Pilgrim)
on Nov 07, 2003 at 01:37 UTC ( [id://305209]=note: print w/replies, xml ) Need Help??


in reply to to generate a set of well contrasted colors

This might be of some help. It is a subroutine I wrote to generate randomly-colored backgrounds for text-on-colored-background pages. The two simple subroutines bg_text() and bg_page() at the bottom illustrate how to use it. I used this method to create the background colors for areas containing text (tables) and areas elsewhere (page background). Pick a contrasting color for the text, or experiment with a different brightness and saturation for randomly-colored text. Some experimentation will be required.
# Subroutine bg_color() creates colors of random hue and fairly # consistent brightness and saturation. The highest and lowest of the # three color channel values are fixed, and the third is given # a random value between the highest and lowest. The three values are # then assigned in random order to red, green, and blue. The highest # value will control the brightness of the resulting color, and the # distance between the highest and lowest will control the saturation. # Hue is randomly set by the value of the random third parameter toget +her # with the random assignment of the three values to red, green, and bl +ue. sub bg_color { my $highest = shift; # lightness my $lowest = shift; # saturation my $middle = int(rand($highest - $lowest) + $lowest); my @c = ($highest, $lowest, $middle); # randomize the order of the three values with the Fisher-Yates shuf +fle my ($i, $j); for ($i = 3; --$i; ) { $j = int rand ($i+1); next if $i == $j; @c[$i,$j] = @c[$j,$i]; } # convert to hex in the form: #RRGGBB my $cs = sprintf "\#%0.2X%0.2X%0.2X", @c; return $cs; } sub bg_text {bg_color(215, 153)}; # light colors, low saturation sub bg_page {bg_color(204, 102)};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found