Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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)};

In reply to Re: to generate a set of well contrasted colors by vacant
in thread to generate a set of well contrasted colors by pg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found