Mastering Perl/Tk says that $widget->rgb(“colour”) gives values from 0 to 255 for the red, green and blue components of the colour.
As the attached Perl shows it seems to give a value approximately the square on these numbers.
I find I can get the range with the expression int(sqrt(red/green/blue)).
The output from the Perl is

colour <black> red <0> green <0> blue <0>
sqrt colour <black> red <0> green <0> blue <0>

colour <white> red <65535> green <65535> blue <65535>
sqrt colour <white> red <255> green <255> blue <255>

colour <red> red <65535> green <0> blue <0>
sqrt colour <red> red <255> green <0> blue <0>

colour <green> red <0> green <65535> blue <0>
sqrt colour <green> red <0> green <255> blue <0>

colour <blue> red <0> green <0> blue <65535>
sqrt colour <blue> red <0> green <0> blue <255>

Can anyone explain why is happening and/or is using the int/sqrt function is the correct thing to do to get the quoted range?
use Tk; use strict "vars"; my (@colours, $col_item, $red, $green, $blue, $mw); $mw = MainWindow->new; @colours = qw(black white red green blue); foreach $col_item (@colours) { ($red, $green, $blue) = $mw->rgb($col_item); print "\n colour <$col_item> red <$red> green <$green> blue <$blue +>\n"; $red = int(sqrt($red)); $green =int(sqrt($green)); $blue = int(sqrt($blue)); print "sqrt colour <$col_item> red <$red> green <$green> blue <$blue>\ +n"; } MainLoop;

In reply to Perl/Tk - query about rdg values of a colour by merrymonk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.