15.1 The Color Registry

The color pickle provides a registry of standard colors, organized as a space of integers. Each integer identifies a standard color, which are accessible as variables named color_* after the pickle is loaded. Example:

(poke) load color
(poke) color_tomato
114

The purpose of having this register is to have a global namespace for colors that can be used in different pickles. The position of each color in the registry is totally unrelated to how the color may be encoded. Other pickles, as we shall see below, contain tables associating standard colors with their encoding, such as RGB.

If you want to add a new color that is not in the standard collection, you can use the color_register function, which gets no arguments:

(poke) var mycolor = color_register
(poke) mycolor
490

The total number of registered colors is recorded in the variable color_num_colors. You can use it to iterate on all the colors in the register, from 0 to color_num_colors - 1.

The index in the registry of the first user-defined color is hold in the variable color_LAST. For example, if you wanted to store a frob per standard color, you would do it like:

(poke) type Frobs = Frob[color_LAST]

The pickle also provides a function color_name that, given a color code, returns a printable name for the color, i.e. a string describing it. For user defined colors, this string is fixed:

(poke) color_name (23)
"lavender blush"
(poke) color_name (color_register)
"user-defined color"

If a non-existent color code is passed to color_name the function raises E_out_of_bounds:

(poke) color_name (color_num_colors)
unhandled out of bounds exception