Examples

The following code fragments use the color spaces to color the polygon in Figure 97. The best way to see these color spaces is to put this code into a TView::DrawContents function, compile it, and run it.


Gray scale

This code fragment takes the following RGB values (.85, .75, .65) that make a light pea green and passes them to the TGrayColor class. These values are equalized to the closest gray scale values. The conversion formula is gray level = (0.3)Red + (0.596)Green + (0.11)Blue. In the example, the gray level is 0.769.

      TRGBColor grayRGBColor( .85, .75, .65 );
      TColorPaint* grayFill = new TColorPaint( TGrayColor( grayRGBColor ) );
      TGrafBundle polyBundle( grayFill, TAttributeState::kFill );
You can also create a gray scale color by supplying a single value that represents the percent of gray. The code line below makes 77 percent gray.

    TColorPaint* grayFill = new TColorPaint( TGrayColor( 0.77 ) );

XYZ color space

In this case, the values (56.7210, 55.3082, 72.4083) are used in the XYZ color space to reproduce the red fill that is obtained in the RGB color space with the values
TRGBColor( .75, .5, .5 ).

    TFillBundle polyBundle( TXYZColor( 56.7210, 5.3082, 72.4083 ) );

HSV color space

The same red fill is obtained in the HSV color space with the following values:

    TFillBundle polyBundle( THSVColor( 0, .3333, .75 ) );

Transforming color spaces

You can work in one color space and easily transform to any other color space. The following code fragments show how you can start in RGB and transform to XYZ and HSV. All color classes have Get functions for retrieving color values.

      TRGBColor redFill( .75, .5, .5 );
      TXYZColor xyzColor( redFill );
      TFillBundle polyBundle( redFill );
      TRGBColor redFill( .75, .5, .5 );
      THSVColor hsvColor( redFill );
      TFillBundle polyBundle( redFill );

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker