Function Repository Resource:

CosColorFunction

Source Notebook

Define color functions based on the cosine function

Contributed by: Michael Sollami

ResourceFunction["CosColorFunction"][a,b,c,d]

returns a color function based on the given parameters.

ResourceFunction["CosColorFunction"][]

creates an interactive panel for designing color palettes.

Details and Options

The arguments a,b,c,d should each be triples of numbers in the interval [0,1].
ResourceFunction["CosColorFunction"] returns a function that gives an RGBColor parameterized by input t, the formula is a+bCos[2π(c t+d)]. As t runs from 0 to 1, the cosine oscillates c times with a phase of d. The result is scaled and biased by a and b to meet the desired contrast and brightness.
ResourceFunction["CosColorFunction"] was originally defined for use in the Graphics Library Shading Language here.

Examples

Basic Examples (1) 

Design a cosine palette:

In[1]:=
ResourceFunction["CosColorFunction"][]
Out[1]=

Scope (1) 

Display palettes with various settings:

In[2]:=
samples = CompressedData["
1:eJxTTMoPSmVmYGBgB2IWIAaxIeCBPWn0Bxw0A4N86+vAHXJX7Qttua4vLnhK
ormEzZ81EwR22kPok1Qz3xgMLsPNpa75D6DmvbQ/ewYE3sDtI9f8NDB4BjX3
Jjx8IOYeptD9DA6o7oeBB2jmXoD7C1X+Jlo43kTTh24+uj0X4OYDAJbflx4=

"];
showPalette[cf_] := DensityPlot[x, {x, 0, 1}, {y, 0, 1}, PlotRangePadding -> None, ImageSize -> {Automatic, 32}, Frame -> False, AspectRatio -> 1/8, PlotPoints -> 100, Mesh -> None, ColorFunction -> cf, ColorFunctionScaling -> False];
ResourceFunction["PrettyGrid"][
 Prepend[ResourceFunction["AppendColumn"][samples, showPalette /@ (ResourceFunction["CosColorFunction"] @@@ samples)],
   Style[#, 13, Italic, Bold] & /@ {"a", "b", "c", "d", "palette"}], Spacings -> {1, .5}, Alignment -> Center]
Out[3]=

Publisher

Michael Sollami

Version History

  • 1.0.0 – 04 May 2020

Related Resources

License Information