7.2 Using color in the Window Tool Kit

7.2.2 Registering colors

You can use the function setup-color-library to 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 functionsetup-color-library with no arguments:

> (setup-color-library) 

If 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)

The function print-color-registry textually 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 invokesetup-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 max-mic-value and min-mic-valueespecify 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

> max-mic-value 65535

Create and register your own red by using this expression:

> (register-color "RED"
      :red max-mic-value :green min-mic-value :blue min-mic-value)

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-value rather than a number.

> (register-color "PINK"
      :red max-mic-value
      :green (round (* .50 max-mic-value))
      :blue max-mic-value)

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.

The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker