-
-
Notifications
You must be signed in to change notification settings - Fork 265
RgbwwColor object API
RgbwwColor represents a color object that is represented by Red, Green, Blue, Warmer White, and Cooler White component values. Its primary use is to contain and manipulate colors for 5 to 6 element Pixels.
Warmer White doesn't necessarily mean Warm White. As Cooler White doesn't necessarily mean Cool White. They are relative to each other so that this object could represent Warm White and Nuetral White or a Nuetral and Cool White also.
There are five properties that represent the component values Red, Green, Blue, Warmer White, and Cooler White. The values range from 0 to 255. Black would 0,0,0,0,0 and white using the color LEDs would be 255,255,255,0,0.
uint8_t R;
uint8_t G;
uint8_t B;
uint8_t WW;
uint8_t CW;
There are also a few constant properties that are helpful to use. These are..
The highest value for a single color element.
const static uint16_t Max = 255;
The number of color elements. Useful when accessing the elements using the [] operators.
const static size_t Count = 5;
Constructs a RgbwColor using Red, Green, Blue, and White component values.
- r - value for the Red component (0 - 255)
- g - value for the Green component (0 - 255)
- b - value for the Blue component (0 - 255)
- warmW - value for the Warmer White component (0 - 255)
- coolW - value for the Cooler White component (0 - 255)
Constructs a RgbwwColor using a single brightness value(0 - 255). This works well for creating gray tone colors.
- brightness - value for the white component where (0) = black, (128) = gray, (255) = white.
This will only affect the white color elements WW and CW, setting them both to this value.
Construct a RgbwwColor using RgbColor, copying the R,G,B values and setting WW and CW to zero.
- color - a RgbColor object.
Construct a RgbwwColor using RgbwColor, copying the R,G,B values while copying the W to both WW and CW.
- color - a RgbwColor object.
Construct a RgbwwColor using HslColor, converting the Hsl to Rgbw
- color - a HslColor object.
Construct a RgbwwColor using HsbColor, converting the Hsb to Rgbw
- color - a HsbColor object.
Construct a RgbwwColor using HtmlColor, converting the HTML to Rgbw
- color - a HtmlColor object.
Construct a RgbwwColor that will have its values set in latter operations.
CAUTION: The R, G, B, WW, and CW members are not initialized and may not be consistent until set.
CalculateBrightness will calculate the overall brightness.
NOTE: For color objects with only WW and/or CW set, it will return average between them. For color objects with WW and CW set to zero this is a simple linear brightness. For color objects with values in WW or CW and another color component, the overall brightness is the brighter of the color components and the average of WW and CW.
Dim will return a new color that is blended to black with the given ratio.
NOTE: This is a simple linear change.
- ratio - (0-255) where 255 will return the original color and 0 will return black.
Brighten will return a new color that is blended to white with the given ratio.
NOTE: This is a simple linear change.
- ratio - (0-255) where 255 will return the original color and 0 will return white.
Darken will adjust the color by the given delta toward black.
NOTE: This is a simple linear change.
- delta - (0-255) the amount to dim the color by.
Lighten will adjust the color by the given delta toward white.
NOTE: This is a simple linear change. If the color only has WW and/or CW values set, only WW and CW will be modified; otherwise only the R,G,B will be modified leaving W alone.
- delta - (0-255) the amount to lighten the color by.
Compares against another color with the given epsilon.
Returns the greatest difference of a set of elements, where 0 means the colors are equal within epsilon delta, negative means this is less than the other, positive means this is greater than the other.
- other - the color to compare against.
- epsilon - the max delta acceptable for them to be considered the same color.
Compares two colors with the given epsilon.
Returns the greatest difference of a set of elements, where 0 means the colors are equal within epsilon delta, negative means left is less than the right, positive means left is greater than the right.
- left - the first color to compare.
- right - the other color to compare.
- epsilon - the max delta acceptable for them to be considered the same color.
This will blend between two colors by the amount defined by the progress variable.
- left - the color to start the blend at.
- right - the color to end the blend at.
- progress - (0.0f - 1.0f) value where 0.0f will return left and 1.0f will return right and a value between will blend the color weighted linearly between them.
This is a static function, which means you need to call it scoped to the object class and not an instance like...
RgbwwColor results = RgbwwColor::LinearBlend(RgbwwColor(255,0,0,0,0), RgbwwColor(0,255,0,10,0), 0.33f);
This will blend between two colors by the amount defined by the progress variable.
- left - the color to start the blend at.
- right - the color to end the blend at.
- progress - (0 - 255) value where 0 will return left and 255 will return right and a value between will blend the color weighted linearly between them.
This is a static function, which means you need to call it scoped to the object class and not an instance like...
RgbwwColor results = RgbwwColor::LinearBlend(RgbwwColor(255,0,0,0,0), RgbwwColor(0,255,0,10,0), 85);
static RgbwwColor BilinearBlend(RgbwwColor c00, RgbwwColor c01, RgbwwColor c10, RgbwwColor c11, float x, float y);
This will blend between four colors by the amount defined by 2d weighting values.
- c00 - upper left quadrant color
- c01 - upper right quadrant color
- c10 - lower left quadrant color
- c11 - lower right quadrant color
- x - unit value (0.0 - 1.0) that defines the blend progress in horizontal space
- y - unit value (0.0 - 1.0) that defines the blend progress in vertical space
The index operator allows accessing the R, G, B, WW, and CW properties using an index. There are both read only and read write versions.
uint8_t warmWhite = color[3];
You can also use the color index constants.
uint16_t warmWhite = color[ColorIndexWW];