Coyote Library Color Programs
These are programs from the Coyote Library that are specifically designed to work with color in IDL graphics routines. Over 50 examples of graphics output (with IDL code) using these color tools can be seen in the Coyote Plot Gallery.
- CINDEX Allows you to see the color index number associated with each color.
- cgCOLOR A program for selecting device-independent colors by names.
- cgCOLOR24 Converts RGB color value to 24-bit integer.
- cgCOLORBAR Creates direct graphics color bar.
- cgCOLORFILL A device-independent and color-independent wrapper for the POLYFILL command.
- cgDCBAR A discrete color bar with a handful of colors and centered labels.
- cgDEFAULTCOLOR This function defines a default color for Coyote Graphics routines.
- cgGETCOLORSTATE This function determines if the graphics device is set to use decomposed or indexed color.
- cgSETCOLORSTATE This command sets the current color state in a device and version independent way.
- cgPICKCOLORNAME Utility for picking or specifying a color by name.
- COLORSAREIDENTICAL Determines if two colors, specified in different ways, are identical.
- FSC_COLORSELECT A compound widget for selecting a color name or color table.
- PICKCOLOR Utility for picking or specifying a drawing color.
- SETDECOMPOSEDSTATE Sets a device/version independent current decomposition state.
- XCOLORS Changes color tables interactively. Absolutely required for 24-bit displays.
|A utility routine for converting a color triple, written
as a three-element column or row vector of the form [red, green, blue],
into a 24-bit long integer. For example, if you were running IDL on a
24-bit display and you wanted to create a plot in a yellow color, you
IDL> Plot, data, Color=Color24([255,255,0])
|A utility routine that allows you to see the color index number assoicated with each color in the current color table. On 24-bit displays, you may need to click the cursor in the color table window to force the colors to update themselves to the current color table. To load colors from this program, you need the XColors program. And for best results, download the cgImage program, as well.|
|A utility routine for determining if two colors refer to the same RGB value. The color may be specified as a color index value, a long integer value, or a color name recognized by cgColor.|
|This program is a completely device-independent program for specifying
colors by name. You can ask for and load any one (or all) of the 88 colors
defined in the program by name. This program replaces the older GetColor program.
The colors available are the ones defined for
the cgPickColorName program:
To see a list of all the colors available by name, type this:
IDL> Print, cgColor(/Names), Format='(5(A14, 2x))' White Snow Ivory Light Yellow Cornsilk Beige Seashell Linen Antique White Papaya Almond Bisque Moccasin Wheat Burlywood Tan Light Gray Lavender Medium Gray Gray Slate Gray Dark Gray Charcoal Black Light Cyan Powder Blue Sky Blue Steel Blue Dodger Blue Royal Blue Blue Navy Honeydew Pale Green Aquamarine Spring Green Cyan Turquoise Sea Green Forest Green Green Yellow Chartreuse Lawn Green Green Lime Green Olive Drab Olive Dark Green Pale Goldenrod Khaki Dark Khaki Yellow Gold Goldenrod Dark Goldenrod Saddle Brown Rose Pink Rosy Brown Sandy Brown Peru Indian Red Chocolate Sienna Dark Salmon Salmon Light Salmon Orange Coral Light Coral Firebrick Brown Hot Pink Deep Pink Magenta Tomato Orange Red Red Violet Red Maroon Thistle Plum Violet Orchid Medium Orchid Dark Orchid Blue Violet Purple
The normal calling sequence for producing device-independent drawing colors, will look similar to this. The first parameter is the name of the color you want, the second parameter is the color table index where you would like to load the specified color.
axisColor = cgCOLOR("Green", !D.Table_Size-2) backColor = cgCOLOR("Dark Gray", !D.Table_Size-3) dataColor = cgCOLOR("Yellow", !D.Table_Size-4) Plot, Findgen(11), Color=axisColor, Background=backColor, /NoData OPlot, Findgen(11), Color=dataColor
If color decomposition is turned off, then the color is loaded at the specified index. If color decomposition is turned on, then no color is loaded into the color table.
If a color index is not specified and color decomposition is turned off, then the specified color is loaded into the !P.Color index.
The output of these commands looks like this:
The value that is returned by cgCOLOR depends upon the keywords used to call it and on the version of IDL you are using. In general, the return value will be either a color index number where the specified color is loaded by the program, or a 24-bit color value that can be decomposed into the specified color on true-color systems.
If you are running IDL 5.2 or higher, the program will determine which return value to use, based on the color decomposition state at the time the program is called. If you are running a version of IDL before IDL 5.2, then the program will return the color index number. This behavior can be overruled in all versions of IDL by setting the DECOMPOSED keyword. If this keyword is 0, the program always returns a color index number. If the keyword is 1, the program always returns a 24-bit color value.
If the TRIPLE keyword is set, the program always returns the color triple, no matter what the current decomposition state or the value of the DECOMPOSED keyword. This is useful, for example, if you want to load a color in the color table yourself.
IDL> TVLCT, cgColor('dodger blue', /Triple), 10
If the ALLCOLORS keyword is used, then instead of a single value, modified as described above, then all the color values are returned in an array. In other words, the return value will be either an NCOLORS-element vector of color table index numbers, an NCOLORS-element vector of 24-bit color values, or an NCOLORS-by-3 array of color triples.
This program can also read an ASCII file of color names and values, so you don't have to use the 88 colors provided.
And if you prefer to have the user select a color name, you can use the SELECTCOLOR keyword. (This requires cgPickColorName.) For example, suppose you want the RGB color triple of a user-supplied color. You would type this:
IDL> color = cgCOLOR(/SelectColor, /Triple) IDL> Print, color
The output keyword COLORSTRUCTURE is useful if you want to get all of the colors in a structure variable with the color names as fields in the structure.
IDL> d = cgCOLOR(/AllColors, ColorStructure=c) IDL> Plot, Findgen(11), Color=c.green, Background=c.charcoal, /NoData IDL> OPlot, Findgen(11), Color=c.dodgerblue
It is also possible to specify a vector of color names. For example, if you are overploting several lines in a plot, and you wish to each to have a different color, you might do this:
IDL> d = cgColor(/AllColors, ColorStructure=c) IDL> Plot, x, y[0,*], Color=c.yellow, Background=c.charcoal, /NoData IDL> colors = cgColor( ['dodger blue', 'indian red', 'pale green'] ) IDL> FOR j=0,2 DO OPlot, x, y[j,*], Color=colors[j]
The plot might look something like this.
Updated 15 May 2008 to use Brewer Colors in addition to the normal colors.
|This program shows you one way to create a colorbar for your programs.
This colorbar appears exactly the same in a PostScript file as
it does on your display.
|This program is a wrapper for the POLYFILL command. It fills a polygon with a color or "texture." Set the WINDOW keyword to add this command to an cgWindow application.|
|This program produces a discrete color bar with a handful, say 3 to 20 colors. Labels
are centered (either horizontally or vertically) for each color, and the labels can be
rotated, if needed, to keep an uncluttered display. The colorbar can be displayed either
horizontally or vertically anywhere in the display window. You can learn more about how
this program works by reading the Discrete Color Bar
article on my web page.
|The purpose of this function is to choose a default color for Coyote Graphics routines. The input can be a string, a byte or integer, or a
long integer. If the input is a long integer, the function will evaluate
the value depending upon the current color state. If using indexed color,
and the long integer is in the range 0-255, the long integer is interpreted as a color table index number. The output is generally passed
to cgColor to obtain the actual
color used in the program.
color = cgDefaultColor(inputColor, Default='Opposite') IF Size(color, /TNAME) EQ 'STRING' THEN color = cgColor(color)
|A blocking or modal dialog widget for selecting a specific color name.
Eighty-eight colors are available. The return value of this function is the new
color name. Keywords allow the loading of this color directly in the
color table. This program requires the cgColor program.
Updated 15 May 2008 to use Brewer Colors.
|This function provides a device-independent way to determine if a graphics device is currently set to use decomposed color (sometimes known as true-color) or to use indexed color. The program was mandated by the introduction of PostScript 24-bit decomposed color in IDL 7.1 without any way to determine programmatically if the PostScript device was currently in 24-bit color mode. The program works identically with WIN, X, MAC, Z, and PS devices, as well as others.|
|This program shows you how to create a colorbar for your programs, but
written as an object. Direct graphics programs written as objects have a number
of advantages. This colorbar, for example, has an Erase method that
can be used to erase the colorbar from the display. Plus, colorbar properties
can be changed and displayed immediately.
The colorbar appears exactly the same in a PostScript file as
it does on your display.
|A modal dialog widget for selecting a specific color. One of 88 pre-defined
color selections can be made, or the user can manipulate slider widgets to create
any RGB color triple. The return value of this function is the new
color triple. The color table on entry is the same as the color table on
exit. You must specifically load the new color for it to take effect.
This program requires the cgColor program.
Updated 15 May 2008 to use Brewer Colors, too. There are now 200 different colors available.
This program set the current color decomposition state of a graphics device in a device-independent and version-independent manner. An output keyword, CurrentState, is availabe to return the current color decomposition state of the device at the time it is set. This avoids a problem with UNIX machines obtaining the state in a different way than Windows machines.
|A widget program for changing color tables, it is similar
to XLOADCT. This program has been extensively modified. In particular,
it now works on 24-bit color displays exactly the way it works on 8-bit displays.
NotifyID, NotifyObj, and NotifyPro keywords allow you to identify other widgets,
objects, or programs that should be notified when the user changes the color tables.
Such notification is essential for updating colors on 24-bit displays.
(See the Color_Example program code for an example of
how this works.) This program is essential for writing "color aware" widget programs.
No common blocks are used, so each graphics window on your display can have its own
color table loading tool if you like. A Cancel button restores the original color
table if you change your mind about the colors you load. This program is essential if you
are loading color tables from widget programs. Updated on 14 May 2008 to support
You will need to download the fsc_brewer.tbl file from
Coyote Library to use this functionality. Install it either in the $IDL_DIR/resource/colors directory
or in any directory in the IDL path.
Version of IDL used to prepare this article: IDL 7.0.1.