View Raw SPL
/*****************************************************************************
*                                                                            *
*   FLAG.SPL   Copyright (C) 2018 DSP Development Corporation                *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Generate red, white, blue, black cmap                       *
*                                                                            *
*   Revisions:   30 Mar 2018  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_FLAG

    FLAG

    Purpose: Generates a red, white, blue, black colormap.

    Syntax:  FLAG(len)

               len - optional colormap length, defaults to
                     the length of the current colormap


    Returns: A table of RGB triples suitable for the SETCOLORMAP function.

    Example:
             clen = length(getcolormap());
             density(ravel(rep(0..(clen-1), 32), clen)');
             flag();

             Creates a table of 32 x colormap length RBG values and
             displays the resulting colors. The resulting image is a
             vertical plot of colors ranging from red (lowest) to
             white, blue, black (highest).

    Example:
             flag(256);showcmap

             Creates a table of 32 x 256 length RBG values and
             displays the resulting colors. The resulting image is a
             vertical plot of colors ranging from red (lowest) to
             white, blue, black (highest).

    Remarks:
             FLAG() by itself sets the colormap and shading.

             a = flag() or setcolormap(flag()) returns the rgb values.
             In this case, use SETSHADING to make the new colormap
             take effect on an existing density or 2D plot.

    See Also:
             Autumn
             Bone
             Cool
             Copper
             Gray
             Hot
             Hsv2rgb
             Parula
             Pink
             Rainbow
             Setcolormap
             Setshading
             Showcmap
             Spring
             Summer
             Winter
#endif


/* flag colormap */
flag(cmaplen)
{
        local rgb;

        if (argc < 1)
        {
                cmaplen = length(getcolormap());
        }

        /* RGB colors */
        rgb = {{1, 0, 0},
               {1, 1, 1},
               {0, 0, 1},
               {0, 0, 0}};

        /* replicate and size to cmaplen */
        rgb = extract(rep(rgb, ceil(cmaplen / 4)), 1, cmaplen);

        if (outargc == 0)
        {
                /* set the colormap and shading */
                setplotshading(rgb);
        }
        else
        {
                /* return the colormap */
                setrgbprops(rgb);

                return(rgb);
        }
}