View Raw SPL
/*****************************************************************************
*                                                                            *
*   GRAY.SPL       Copyright (C) 1997 DSP Development Corporation            *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Generate a grayscale colormap                               *
*                                                                            *
*   Revisions:    6 Nov 1997  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_GRAY

    GRAY

    Purpose: Generates a black & white colormap

    Syntax:  GRAY(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)');
             gray();

             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 black (lowest) to
             to white (highest).

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

             a = gray() or setcolormap(gray()) 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
             Cool
             Hot
             Parula
             Rainbow
             Spring
             Summer
             Winter
             Setcolormap
             Setshading
             Showcmap

#endif


/* gray colormap */
gray(mlen)
{
        local bw, cmap;

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

        /* generate black and white rgb values */
        bw = (0..(mlen - 1)) / max(1, mlen - 1);

        cmap = ravel(bw, bw, bw);

        if (outargc == 0)
        {
                setplotshading(cmap);
        }
        else
        {
                /* return the colormap */
                setrgbprops(cmap);

                return(cmap);
        }
}