7.2 Using color in the Window Tool Kit
setup-color-libraryto register additional colors from the color library, and you can register individual colors yourself.
You can automatically register the primary colors--red, green, blue, yellow, magenta, cyan--by invoking the function
setup-color-library with no arguments:
> (setup-color-library) NILIf you need more than the primary colors, you can install all of the possible colors in the color library with the following expression:
> (setup-color-library :extended-colors t) NILThe function
print-color-registrytextually displays all currently registered colors, as well as other information about each color.
Once you have registered a color under a specific name, you cannot register it again unless it has been deleted. Thus, you can invoke
setup-color-library repeatedly without any ill effects.
You can also register your own colors by using the function
register-color. To create your own colors, you must specify the amount of red, green, and blue light that produces the desired shade of color when mixed. You can produce any color by using various amounts, or saturations, of each of these colors. This system of representing color with light is referred to as the red/green/blue (RGB) system.
For example, you can make the color
"RED" by mixing the maximum value possible for red with the minimum value for green and blue. The constants
especify the maximum and minimum values possible for color saturation when registering a color. These values for color saturation are machine independent for any color hardware system that supports the Window Tool Kit.
> min-mic-value 0Create and register your own red by using this expression:
> max-mic-value 65535
> (register-color "RED" :red max-mic-value :green min-mic-value :blue min-mic-value) "RED"If you want a color that is some percentage of the maximum possible saturation, it is generally simpler (and better coding style) to use some percentage of
max-mic-valuerather than a number.
> (register-color "PINK" :red max-mic-value :green (round (* .50 max-mic-value)) :blue max-mic-value) "PINK"Notice that pink is like the primary color magenta--it has a full saturation of red and blue; however, pink also has 50% saturation of green, while magenta has no green at all. Black has no RGB saturation, and white has complete saturation of red, green, and blue. Grey has equal parts of red, green, and blue. While mixing colors is not quite like mixing paints, with a little experimentation it becomes easier. Section 7.4 on page 77 contains palette code that can help you mix your own shades of colors.
Generated with Harlequin WebMaker