COLSET (Command)

is a command which alters which colours are available to the graphics system. It has three parameters. The first is a string, and should be,  , or   (anything else results in   error). The second is a number, which is rounded down to an integer, and the rounded value should be between 0 and 255 inclusive (anything else results in  error). The third is a string of six hexadecimal characters (upper and lowercase are both permitted) (anything else results in  error.)

The first pair of hexadecimal digits refers to an intensity of red, the second pair to an intensity of green, and the third pair to an intensity of blue. Though there is 8 bits of accuracy in a pair of hexadecimal digits, the red and blue values are only stored to 5 bits of accuracy, and green is stored to 6 bits of accuracy. So, for example, if "03" is used in COLSET, then COLREAD on the colour will give a result of 0, but if "08" is used, COLREAD will give the value 8.

The following tables give the relationship between values written using COLSET, and values read using COLREAD.

For R or B values: The above table can be summarized as follows. For any value on the bottom row, round it down to the nearest multiple of 8, multiply by 255/248, then round to the nearest integer. For G values, there is a similar table, except the steps are to round down to the nearest multiple of 4, multiply by 255/252, then round to the nearest integer.

(This kind of conversion happens when you wish to quantize a range of values to a smaller set: the set of values 0 to 255 is divided into equal partitions, and each partition is given an integer number spaced as evenly as possible so the lowest is 0 and the highest is 255. Consider the smaller example of the range from 0 to 7, partitioned into 4 sets.  Each set will be two numbers: {0, 1}, {2, 3}, {4, 5}, {6, 7}.  The lowest number is 0, the highest is 7, there are 4 numbers, so the most regular way to associate numbers with the partitions is 0, 2, 5, 7.  So, 0 to 1 becomes 0, 2 to 3 becomes 2, 4 to 5 becomes 5, and 6 to 7 becomes 7.)