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


#if @HELP_PRISM

    PRISM

    Purpose: Generates a red, orange, yellow, green, blue, magenta colormap.

    Syntax:  PRISM(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)');
             prism();

             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
             orange, yellow, green, blue, magenta (highest).

    Example:
             prism(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
             orange, yellow, green, blue, magenta (highest).

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

             a = prism() or setcolormap(prism()) 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


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

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

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

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

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