View Raw SPL
/*****************************************************************************
* *
* HSV.SPL Copyright (C) 2018 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Generate red, yellow, green, cyan, blue, magenta, red cmap *
* *
* Revisions: 30 Mar 2018 RRR Creation *
* *
*****************************************************************************/
#if @HELP_HSV
HSV
Purpose: Generates a red, yellow, green, cyan, blue, magenta, red colormap.
Syntax: HSV(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 red (lowest) to
yellow, green, cyan, blue, magenta and back to red.
Example:
hsv(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
yellow, green, cyan, blue, magenta and back to red.
Remarks:
HSV() by itself sets the colormap and shading.
a = hsv() or setcolormap(hsv()) returns the rgb values.
In this case, use SETSHADING to make the new colormap
take effect on an existing density or 2D plot.
HSV creates a colormap by linearly varying the hue portion of a
colormap where the saturation and lightness components
remain constant.
See Also:
Autumn
Bone
Cool
Copper
Gray
Hot
Hsv2rgb
Parula
Pink
Rainbow
Setcolormap
Setshading
Showcmap
Spring
Summer
Winter
#endif
/* hsv colormap */
hsv(cmaplen)
{
local rgb, hsv;
if (argc < 1)
{
cmaplen = length(getcolormap());
}
/* HSV colors */
hsv = (0..(cmaplen - 1)) / max(1, cmaplen - 1);
/* convert to rgb */
rgb = hsv2rgb(ravel(hsv, ones(cmaplen, 2)));
if (outargc == 0)
{
/* set the colormap and shading */
setplotshading(rgb);
}
else
{
/* return the colormap */
setrgbprops(rgbp);
return(rgb);
}
}