• From: gtk-list optosun7 city ac uk (J. Ali Harlow)
• Date: Sun, 8 Apr 2001 15:29:13 +0100

On Sun, 08 Apr 2001, Valery Avaux wrote:
Hello,

I use a drawing area with 2 colors red and blue. But I don't know to get
other colors . For these two I use the following defintion that were
given me.

blue.red   = 0;
blue.green = 0;
blue.blue  = 0xff * 0x100;
gdk_colormap_alloc_color(colormap, &blue, FALSE, TRUE);

red.red   = 0xff * 0x100;
red.green = 0;
red.blue  = 0;

Could someone explain how to get other colors (for example white) ?

Monitors are light based. Thus you create colours in exactly the way
you would when mixing colours from spotlights (assuming you were taught
this in physics classes where you are):

Red + Green = yellow
Green + Blue = cyan
Blue + Red = magenta
Red + Green + Blue = white

If you've got a copy of rgb.txt (ie., in /usr/X11R6/lib/X11/rgb.txt) this has
X11's list of colour names and values for red, green and blue. You'll want to
scale these from 0-255 to 0-65535 (as you have done above by multiplying by
0x100).

For example, rgb.txt contains the line:

46 139  87             SeaGreen

So we might create this using:

seagreen.red = 46 * 0x100;
seagreen.green = 139 * 0x100;
seagreen.blue = 87 * 0x100;

(some people prefer to multiply by 257 rather than 0x100 (256) because it gives
better scaling. ie., 255 * 257 = 65535.)

--
Ali Harlow                              Email: ali avrc city ac uk
Research programmer                     Tel:   (020) 7477 8000 X 4348
Applied Vision Research Centre          Intl: +44 20 7477 8000 X 4348
City University                         Fax:   (020) 7505 5515
London                                  Intl: +44 20 7505 5515