Color Utils - AlbertGBarber/PixelSpork GitHub Wiki
Jump to:
Intro:
This page lists various functions for manipulating CRGB colors. They mostly deal with blending multiple colors together or fetching colors from a rainbow. These functions are stored under the namespace, colorUtilsPS
.
An example of using the namespace to call randColor()
:
CRGB myColor = colorUtilsPS::randColor(); //sets myColor to a random color
You can also find these functions in "colorUtilsPS.h" and "colorUtilsPS.cpp".
Random Color Range Settings:
Pixel Spork has a simple random color function, randColor()
. The function returns a CRGB color using HSV color values, randomizing the hue completely, while randomizing the saturation between a limited range.
The range settings are:
-
uint8_t randSatMin (default 100) -- The minimum possible saturation. Must be less than
randSatMax
. -
uint8_t randSatMax (default 255) -- The maximum possible saturation.
These variables are static within the namespace, so you can change their values to control how random colors are chosen for your whole program. Their defaults seem to produce a good mix of colors, trending towards the pastel side. Note that their ranges are 0 to 255 (in place of the typical HSV 0 to 360), with 255 being fully saturated.
The randColor()
function is the standard color generating function for effects and utilities, so changes to the ranges will affect color generation across the library.
To change a range value you would:
colorUtilsPS::randSatMin = 150;
//changes the minimum saturation to 150.
Note that I do not give you a HSV "value" range (it is maxed at 255) because tweaking the value only seems to dim colors without changing them significantly. However, Pixel Spork also provides an alternate random color function, with fully customizable ranges for both saturation and value (see below).
Functions:
-
CRGB randColor();
Returns a random color using a random hue and a limited random saturation (from 100 to 255 by default, see "Random Color Ranges" in intro) using HSV colors. Seems to produce a good set of random colors, tending towards more pastel type colors. Note that it doesn't randomize the HSV "value" because doing so mostly just dims the output colors without significantly changing them.
-
CRGB randColor(uint8_t satMin, uint8_t satMax, uint8_t valMin, uint8_t valMax);
Returns a random color from the HSV spectrum. The ranges
satMin
tosatMax
andvalMin
tovalMax
set the random ranges for the HSV "saturation" and "value". For example, ifsatMin
is 50 andsatMax
is 255, the random color's saturation will be between 50 and 255. The ranges run from 0 to 255, with 255 being full saturation/value. -
CRGB getCompColor(uint8_t baseHue, uint8_t numColors, uint8_t num, uint8_t sat, uint8_t val);
Returns a complimentary color to the supplied in hue,
baseHue
, using HSV colors.numColors
is the type of split, ie complementary is 2, triad is 3, tetrad is 4, etc (can't do split complementary).num
is the number of the color in the split you want, ie for a triad you'd ask for colorsnum
0, 1, or 2.sat
andval
are the saturation and value for the color (see HSV link). -
CRGB wheel(uint16_t hue, uint16_t hueOffset);
Returns a color from the HSV rainbow spectrum at a specific
hue
. Uses FastLED's HSV color system, so thehue
range is 0 - 255. (Ignore thathue
is a uint16_t, this is done for compatibility reasons, and may be switched to uint8_t once I do some testing). Saturation and value are both set to their maxes at 255.hueOffset
offsets thehue
value and is primarily used to shift rainbows over time. Leave it at 0 otherwise. -
CRGB wheel(uint16_t hue, uint16_t hueOffset, uint8_t sat, uint8_t val);
Returns a color from the HSV rainbow spectrum like the previous "wheel" function, but includes modifiers for the rainbow's "value" and "saturation",
val
andsat
respectively. -
CRGB getCrossFadeColor(const CRGB &startColor, const CRGB &endColor, uint8_t blendStep, uint8_t totalSteps);
Returns a color that is blended from the
startColor
toendColor
by the ratioblendStep / totalSteps
. Note that the maximum total steps is 255. For example, if I wanted to blend halfway between red and green using 20 steps, I would callgetCrossFadeColor(CRGB::Red, CRGB::Green, 10, 20)
. -
CRGB getCrossFadeColor(const CRGB &startColor, const CRGB &endColor, uint8_t ratio);
Same as
getCrossFadeColor()
above, but you pass in the blend ratio directly asratio
. Theratio
range is 0 - 255, with 255 being a total conversion to the end color. -
CRGB dimColor(const CRGB &color, uint8_t ratio);
Returns a color faded to black by a certain
ratio
. Theratio
range is 0 - 255, with 255 being a total conversion to black. -
uint8_t getCrossFadeColorComp(uint8_t startColor, uint8_t endColor, uint8_t ratio);
Returns a value between two uint8_t's interpolated by the
ratio
. Theratio
range is 0 - 255, with 255 being a total conversion to the end value. May be useful for blending individual RGB components.