Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Option 1 - maximum contrast for black and white, fading to no contrast for middle gray: For each component, R, G, & B, subtract the current value from 255. reassamble into a colour - there's your complementary colour. If you haven't defined the format for a tuple, yet, I suggest using anonymous arrays. In any case, you'll need routines to do format conversions.

$c1 = [ $r, $g, $b ]; $c2 = contrasting_colour( @c1 ); sub contrasting_colour { my ( $c ) = @_; my ( $r, $g, $b ) = ( 255 - $c->[0], 255 - $c->[1], 255 - $c->[2] ); return [ $r, $g, $b ]; } sub rgb2hash { my ( $c ) = @_; my ( $r, $g, $b ) = ( 255 - $c->[0], 255 - $c->[1], 255 - $c->[2] ); return sprintf "#%02X%02X%02X", $r, $g, $b; }

Option 2 - less, but reasonable contrast for all values. Add half the range, 128, to each of R, G, B, rolling over values that go out of range. Black and white both go to middle grey, middle grey goes to white

sub contrasting_colour { my ( $c ) = @_; my ( $r, $g, $b ) = ( ($c->[0] + 128) % 256, ($c->[1] + 128) % 256, ($c->[2] + 128) % 256, ); return [ $r, $g, $b ]; }

Option 3 - Modify each of R, G, B by a varying amount, between 1/3 and 2/3 full range. As a consequence, looking for ten contrasting colours for black would generate ten different colours between dark grey and light grey, providing some degree of actual colour as well as monochrome. This provides fair contrast, but no repeatability.

In reply to Re: Contrasting Colours by TomDLux
in thread Contrasting Colours by msemtd

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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2023-09-29 23:51 GMT
Find Nodes?
    Voting Booth?

    No recent polls found