Next: 7.12 Optimal triangulation of Up: 7. Creating GMT Graphics Previous: 7.10 A geographical bar Contents Index

#
7.11 Making a 3-D RGB color cube

In this example we generate a series of 6 color images, arranged so that they can be cut out and assembled into a 3-D color cube. The six faces of the cube represent the outside of the R-G-B color space. On each face one of the color components is fixed at either 0 or 255 and the other two components vary smoothly across the face from 0 to 255. The cube is configured as a right-handed coordinate system with x-y-z mapping R-G-B. Hence, the 8 corners of the cube represent the primaries red, green, and blue, plus the secondaries cyan, magenta and yellow, plus black and white.

The 6 color faces are generated by feeding grdimage three grids, one for each color component (R, G, and B). In some cases the X or Y axes of a face are reversed by specifying a negative width or height in order to change the variation of the color value in that direction from ascending to descending, or vice versa.

A number of rays emanating from the white and black corners indicate the Hue value (ranging from 0 to 360°). The dashed and dotted lines near the white corner reflect saturation levels, running from 0 to 1 (in black font). On these 3 faces the brightness is a constant value of 1. On the other 3 faces of the cube, around the black corner, the white decimal numbers indicate brightnesses between 0 and 1, with saturation fixed at 1.

Here is the shell script to generate the RGB cube in Figure 7.11:

    #!/bin/sh
    #               GMT EXAMPLE 11
    #
    # Purpose:      Create a 3-D RGB Cube
    # GMT progs:    gmtset, grdimage, grdmath, pstext, psxy
    # Unix progs:   rm
    ps=example_11.ps

    # Use psxy to plot "cut-along-the-dotted" lines.

    gmtset TICK_LENGTH 0 COLOR_MODEL rgb CHAR_ENCODING Standard+

    psxy cut-here.dat -Wthinnest,. -m -R-51/306/0/1071 -JX3.5i/10.5i -X2.5i -Y0.5i \
            -P -U/-2.0i/-0.2i/"Example 11 in Cookbook" -K > $ps

    # First, create grids of ascending X and Y and constant 0.
    # These are to be used to represent R, G and B values of the darker 3 faces of the cube.

    grdmath -I1 -R0/255/0/255 X = x.grd
    grdmath -I1 -R Y = y.grd
    grdmath -I1 -R 0 = c.grd

    grdimage x.grd y.grd c.grd -JX2.5i/-2.5i -R -K -O -X0.5i >> $ps
    psxy -m -Wthinner,white,- rays.dat -J -R -K -O -Bwesn >> $ps
    echo 128 128 12 -45 1 MC "60\217" | pstext -Gwhite -J -R -K -O >> $ps
    echo 102 26 12 -90 1 MC 0.4 | pstext -Gwhite -J -R -K -O >> $ps
    echo 204 26 12 -90 1 MC 0.8 | pstext -Gwhite -J -R -K -O >> $ps
    echo 10 140 16 180 1 MC G | pstext -Gwhite -J -R -K -O >> $ps
    echo 0 0 0 128 | psxy -N -Svs -Gwhite -J -R -K -O >> $ps

    grdimage x.grd c.grd y.grd -JX2.5i/2.5i -R -K -O -Y2.5i >> $ps
    psxy -m -Wthinner,white,- rays.dat -J -R -K -O -Bwesn >> $ps
    echo 128 128 12 45 1 MC "300\217" | pstext -Gwhite -J -R -K -O >> $ps
    echo 26 102 12 0 1 MC 0.4 | pstext -Gwhite -J -R -K -O >> $ps
    echo 26 204 12 0 1 MC 0.8 | pstext -Gwhite -J -R -K -O >> $ps
    echo 140 10 16 -90 1 MC R | pstext -Gwhite -J -R -K -O >> $ps
    echo 100 100 16 -45 1 MC V | pstext -Gwhite -J -R -K -O >> $ps
    echo 0 0 128 0 | psxy -N -Svs -Gwhite -J -R -K -O >> $ps
    echo 0 0 90 90 | psxy -N -Svs -Gwhite -J -R -K -O >> $ps

    grdimage c.grd x.grd y.grd -JX-2.5i/2.5i -R -K -O -X-2.5i >> $ps
    psxy -m -Wthinner,white,- rays.dat -J -R -K -O -Bwesn >> $ps
    echo 128 128 12 135 1 MC "180\217" | pstext -Gwhite -J -R -K -O >> $ps
    echo 102 26 12 90 1 MC 0.4 | pstext -Gwhite -J -R -K -O >> $ps
    echo 204 26 12 90 1 MC 0.8 | pstext -Gwhite -J -R -K -O >> $ps
    echo 10 140 16 0 1 MC B | pstext -Gwhite -J -R -K -O >> $ps
    echo 0 0 0 128 | psxy -N -Svs -Gwhite -J -R -K -O >> $ps
    echo 0 0 128 0 | psxy -N -Svs -Gwhite -J -R -K -O >> $ps

    # Second, create grids of descending X and Y and constant 255.
    # These are to be used to represent R, G and B values of the lighter 3 faces of the cube.

    grdmath -I1 -R 255 X SUB = x.grd
    grdmath -I1 -R 255 Y SUB = y.grd
    grdmath -I1 -R 255       = c.grd

    grdimage x.grd y.grd c.grd -JX-2.5i/-2.5i -R -K -O -X2.5i -Y2.5i >> $ps
    psxy -m -Wthinner,black,- rays.dat -J -R -K -O -Bwesn >> $ps
    echo 128 128 12 225 1 MC "240\217" | pstext -J -R -K -O >> $ps
    echo 102 26 12 270 1 MC 0.4 | pstext -J -R -K -O >> $ps
    echo 204 26 12 270 1 MC 0.8 | pstext -J -R -K -O >> $ps

    grdimage c.grd y.grd x.grd -JX2.5i/-2.5i -R -K -O -X2.5i >> $ps
    psxy -m -Wthinner,black,- rays.dat -J -R -K -O -Bwesn >> $ps
    echo 128 128 12 -45 1 MC "0\217" | pstext -J -R -K -O >> $ps
    echo 26 102 12 0 1 MC 0.4 | pstext -J -R -K -O >> $ps
    echo 26 204 12 0 1 MC 0.8 | pstext -J -R -K -O >> $ps
    echo 100 100 16 45 1 MC S | pstext -Gblack -J -R -K -O >> $ps
    echo 204 66 16 90 1 MC H | pstext -Gblack -J -R -K -O >> $ps
    echo 0 0 90 90 | psxy -N -Svs -Gblack -J -R -K -O >> $ps
    echo 204 204 204 76 | psxy -N -Svs -Gblack -J -R -K -O >> $ps

    grdimage x.grd c.grd y.grd -JX-2.5i/2.5i -R -K -O -X-2.5i -Y2.5i >> $ps
    psxy -m -Wthinner,black,- rays.dat -J -R -K -O -Bwesn >> $ps
    echo 128 128 12 135 1 MC "120\217" | pstext -J -R -K -O >> $ps
    echo 26 102 12 180 1 MC 0.4 | pstext -J -R -K -O >> $ps
    echo 26 204 12 180 1 MC 0.8 | pstext -J -R -K -O >> $ps
    echo 200 200 16 225 1 MC GMT 4 | pstext -J -R -O >> $ps

    rm -f *.grd .gmt*

Figure 7.11: The RGB color cube.

Next: 7.12 Optimal triangulation of Up: 7. Creating GMT Graphics Previous: 7.10 A geographical bar Contents Index