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.
KPV - here's that list, along with the closest named Tk color:
W3C NAME RGB Closest TK color (~ means not an exact match) black #000000 => black silver #C0C0C0 => ~gray75 (or SystemButtonFace on classic Windows) gray #808080 => ~gray50 white #FFFFFF => white maroon #800000 => ~darkred red #FF0000 => red purple #800080 => ~DarkMagenta fuchsia #FF00FF => magenta green #008000 => ~green4 lime #00FF00 => green olive #808000 => ~Gold4 yellow #FFFF00 => yellow navy #000080 => navy blue #0000FF => blue teal #008080 => ~turquoise4 aqua #00FFFF => cyan
NB. what TK calls green is actually lime for W3C
MGS 2003/03/21 - These are not the "web-safe" colors - they are the 16 colors defined in HTML 3.2 and 4.01 and correspond to the basic VGA set on PCs. The "browser-safe" colors are constructed from colors where red, green and blue are restricted to the values:
RGB 00 51 102 153 204 255 HEX 00 33 66 99 CC FF
... which gives about 216 different colors, if I can count properly (unlikely).
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.
Random color: EE presented this simple beauty in the Tcl chatroom on 2002-12-18:
proc randomColor {} {format #%06x [expr {int(rand() * 0xFFFFFF)}]}