Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

Using Color


The color of a graphic object is specified by the COLOR property of that object. You can set the color of an object either when the object is created or afterwards. For example, the following statement creates a view object and sets its color value to the RGB triple [60, 60, 60] (a dark gray).

myView = OBJ_NEW('IDLgrView', COLOR = [60, 60, 60]) 

The following statement changes the color value of an existing axis object to the color value specified for entry 100 in the color palette associated with the axis object.

myAxis->SetProperty, COLOR=100 

Remember that color palettes associated with individual graphic atoms are only used when the destination object uses an RGB color model.

Specifying RGB Values

RGB values are specified with RGB triples. An RGB triple is a three-element vector of integer values, [r, g, b], generally ranging between 0 and 255. A value of zero is the darkest possible value for each of the three channels-thus an RGB triple of [0, 0, 0] represents black, [0, 255, 0] represents bright green, and [255, 255, 255] represents white.

For example, suppose we create a plot line with the following statements:

myWindow = OBJ_NEW('IDLgrWindow') 
myView = OBJ_NEW('IDLgrView', VIEWPLANE_RECT=[0, 0, 10, 10]) 
myModel = OBJ_NEW('IDLgrModel') 
myPlot = OBJ_NEW('IDLgrPlot', FINDGEN(10), THICK = 5, $ 
   COLOR=[255, 255, 255]) 
myModel->Add, myPlot 
myView->Add, myModel 
myWindow->Draw, myView 

Notice the following aspects of the above example:

  1. The newly-created window (destination) object uses an RGB color mode (the default).
  2. The default color of the view object-the background against which the plot line is drawn-is white ([255, 255, 255]).
  3. The default color of the plot object (and all objects, for that matter) is black. This means that it is necessary to specify a color other than black for the object if we wish it to show up against the black background.

Try changing the colors with the following statements:

myPlot->SetProperty, COLOR = [150, 0, 150] 
myView->SetProperty, COLOR = [75, 250, 75] 
myWindow->Draw, myView 

Home | Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]