An X11 Color Picker



This is a little color picker that I designed to take the place of the standard xco color picker in Solaris 2.5.1.




I originally had the script read the rgb.txt file and parse it on the fly, but the Tcl plug-in for Netscape is disallowing that access. (So far. . .)
I parsed the rgb.txt file, and dropped the name/value pairs into two lists. These lists follow the rgb.txt file as to how the colors are arranged, which is perhaps not how I might order them, but is still pretty good. The file is now only 189 lines (down from ~2400, with all the r/g/b/name values in an array). Two of those lines are *very* long, though. . .

The sliders in the top left of the color picker manipulate the red, green, and blue indices of the color directly, on a scale of 0 to 255 (256 levels for each slider). The changes are immediately displayed in both the display button (the "Pick Your Col or" square) and the hexidecimal display below it. The hexidecimal display also has the advantage of copying directly into your middle button paste buffer, on a three-button mouse X11-using machine. (I haven't tested this functionality yet on any other pla tforms; suggestions?)

In addition to the sliders, I have provided color swatches of all the standard, named X11 colors in the bottom section. Clicking on a color swatch will set the color of the display square on the top, and adjust the hexidecimal display and the sli ders accordingly. I tried to make the name label of the swatches display in either black or white depending on the lightness of the color. The algorithm I used is based on the sum of the differences between the RGB values, and the sum of those values them selves. If someone has a patented algorithm for determining the relative lightness/darkness of an RGB color, I'd like to hear about it.

To Do's:

I had a lot of fun porting this script over. From initial "I wonder if it'd work" to this document was the work of about an hour. (I did have a working stand alone script already.) The ease of porting the script was startling and gratifying.


spencera@cs.uoregon.edu