Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Background: I wanted a way of displaying some html with different shading depending on a given criterion. I didn't want completely different colors - 1 color with different levels of brightness.

This snippet will convert a hex color to RGB, shift the levels up and down by a given value, then convert back to HTML valid HEX (not necessarily web-safe). It returns:
1. lighter color than orig. 2. darker color than orig.

Potential Uses: Well, I am using this for a diary system, the cells in the month-view-calendar will be shaded diferently depending on how many meetings\reminders I have on that day. But I am sure you can thing of other reasons to do it.

Notes: It might not work so well when any of the RGB values are close to 0 or 255. There may also be a neater way of doing it.... Comments welcome...
my $silver = "c0c0c0"; my ($light_silver, $dark_silver) = color_munge(25,$silver); sub color_munge { my @limits = (0, 255); my $off_set = shift; my $html_colour = shift; my @old = map hex, ($html_colour =~ /(..)(..)(..)/); my $brighter = join ('', map {$_ += $off_set; $_ = $limits[1] if $ +_ > $limits[1]; sprintf("%02X", $_); } @old); my $darker = join('', map {$_ -= 2 * $off_set; $_ = $limits[0] if +$_ < $limits[0]; sprintf("%02X", $_); } @old); return ($brighter,$darker); }

In reply to Shading with HTML colors - color_munge by $code or die

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 admiring the Monastery: (9)
As of 2024-04-18 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found