Version 9 of colors

Updated 2002-06-19 15:51:46

Along with the color values available for syntactic use in Tcl scripts, several other facts about color might interest programmers. This page aims to collect all this sort of information.


Okay, here's the standard (and rather reliably portable) 6x6x6 color cube. This page has been around forever:

   http://the-light.com/colclick.html

The source file which realizes the description which appears in the hyperlink at the top of this page is xlib/xcolor.c. X11 (Unix) systems often have a showrgb command and/or .../lib/X11/rgb.txt which give the same (?) data. Programmatic access to the English-to-RGB-code map is available as

  winfo rgb . $color



chooseColor answers some questions on this subject.


The W3C maintains a list [L1 ] of "Web-safe" colors.


xcolors is an interesting command under X11.


International Color Consortium maintains a page [L2 ] which has information on ICC color profiles for computer color matching.

Mildly related to this is "Selecting visually different RGB colors".


Percent to color: The following routine produces a color from an integer between 0 and 100, where 0 is red, 50 is yellow, and 100 is green (useful e.g. for painting progress bars):

 proc percent2rgb {n} {
    # map 0..100 to a red-yellow-green sequence
    set n     [expr {$n < 0? 0: $n > 100? 100: $n}]
    set red   [expr {$n > 75? 60 - ($n * 15 / 25) : 15}]
    set green [expr {$n < 50? $n * 15 / 50 : 15}]
    format    "#%01x%01x0" $red $green
 } ;# RS

"Color manipulation" [L3 ] is the name of an ASPN recipe.


Tk syntax help - Arts and crafts of Tcl-Tk programming - Category Command