View Raw SPL
/*****************************************************************************
*                                                                            *
*   SPRING.SPL   Copyright (C) 2018 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Generate a colormap of magenta, yellow                      *
*                                                                            *
*   Revisions:   30 Mar 2018  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_SPRING

    SPRING

    Purpose: Generates a colormap from magenta to yellow.

    Syntax:  SPRING(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)');
             string();

             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 magenta (lowest) to
             yellow (highest).

    Example:
             spring(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 magenta (lowest) to
             yellow (highest).

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

             a = spring() or setcolormap(spring()) 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
             Hsv
             Parula
             Pink
             Rainbow
             Setcolormap
             Setshading
             Showcmap
             Summer
             Winter
#endif


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

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

        /* RGB colors */
        rgb = (0..(cmaplen - 1)) / max(1, cmaplen - 1);

        rgb = ravel(ones(cmaplen, 1), rgb, 1 - rgb);

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