Next: 5.2 Stereoscopy
Up: 5 Graphics
Prev: 5 Graphics
Contents
We will now see how to construct a color on a terminal which permits it.
In the preceding subroutines, the colors were designated by integer numbers. 0 corresponds to the background color. For a terminal with N colors, the numbers lying between 1 and N-1 correspond to the different colors in the terminal's color table. This color table is, in general, initialized after the output terminal is selected. It is however possible to modify it of to set a color equal to the current color.
Let us first recall some preliminary notions regarding colors.
On a color terminal with a cathodic-ray tube, the different colors are obtained by the combination of the three basic colors: RED, GREEN and BLUE (RGB).
RED + GREEN = YELLOW RED + BLUE = MAGENTA GREEN + BLUE = CYAN RED + GREEN + BLUE = WHITE
The intermediary colors are obtained by putting a multiplicative factor, between 0. and 1., with each of the basic colors. So, let X, Y and Z be 3 numbers between 0. and 1., then we can obtain all the possible colors and vary them by using the following equation:
We call the colors additive, as they are obtained by adding the basic colors.
Figure 5.1: RGB coordinate system
The above is no longer true for a printer type color terminal. The basic colors are the following: MAGENTA, YELLOW and CYAN. The colors are no longer additive, but subtractive:
MAGENTA + YELLOW = RED MAGENTA + CYAN = BLUE YELLOW + CYAN = GREEN MAGENTA + YELLOW + CYAN = BLACK
Here too, by combining the three basic colors linearly, all the colors can be obtained.
FORTRAN 3D functions with the RGB system.
In certain applications, it can be desirable to work in cylindrical coordinates. We change therefore to the "HSV" (Hue, Saturation and Value) coordinate system.
Figure 5.2: Two possible representations of the HSV coordinate system
SUBROUTINE HSVRGB(H, S, V, R, G, B) REAL H, S, V, R, G, B
converts a color described in HSV (H, S, V) into RGB (R, G, B).
SUBROUTINE RGBHSV(R, G, B, H, S, V) REAL H, S, V, R, G, B
converts a color described in RGB (R, G, B) into HSV (H, S, V).
SUBROUTINE SETCOL(R, V, B) REAL R, V, B
Variables R, G and B lie between 0. and 1., and play the same role as X, Y and Z above (figure 5.1). This subroutine sets R, G and B equal to the current color.
SUBROUTINE SETTBC(R, G, B, I1, I2, IRET) INTEGER I1, I2, IRET REAL R(I2-I1+1), G(I2-I1+1), B(I2-I1+1)
restricts, in the color table , R, G and B to lie between indices I1 and I2
inclusively
(the three arrays contain the numbers lying between 0 and 1).
If the color table can be modified, IRET = 0, of not IRET 0.
The index 0 corresponds to a background color.