diff --git a/Rgbw64Color-object-API.md b/Rgbw64Color-object-API.md new file mode 100644 index 0000000..32616c8 --- /dev/null +++ b/Rgbw64Color-object-API.md @@ -0,0 +1,117 @@ +Rgbw64Color represents a color object that is represented by Red, Green, Blue, and White component values. Its primary use is to contain and manipulate colors for 4 element Pixels with 16bit resolution. + +## Properties +There are three properties that represent the component values Red, Green, Blue, and White. The values range from 0 to 65535. Black would 0,0,0,0 and white using the color LEDs would be 65535,65535,65535,0 and white using the white LED would be 0,0,0,65535. + +``` +uint16_t R; +uint16_t G; +uint16_t B; +uint16_t W; +``` + +There are also a few constant properties that are helpful to use. These are.. +#### Max +The highest value for a single color element. +``` + const static uint16_t Max = 65535; +``` +#### Count +The number of color elements. Useful when accessing the elements using the [] operators. +``` + const static size_t Count = 4; +``` +## Constructors + +### Rgbw64Color(uint16_t r, uint16_t g, uint16_t b, uint16_t w) : +Constructs a Rgbw64Color using Red, Green, Blue, and White component values. +> * _r_ - value for the Red component (0 - 65535) +> * _g_ - value for the Green component (0 - 65535) +> * _b_ - value for the Blue component (0 - 65535) +> * _w_ - value for the White component (0 - 65535) + +### Rgbw64Color(uint16_t brightness) +Constructs a Rgbw64Color using a single brightness value(0 - 65535). This works well for creating gray tone colors. +> * _brightness_ - value for the white component where (0) = black, (21845) = gray, (65535) = white. +This will only affect the W color element. + +### Rgbw64Color(RgbColor color); +Construct a Rgbw64Color using RgbColor, converting the R,G,B values and setting W to zero. +> * _color_ - a RgbColor object. + +### Rgbw64Color(RgbwColor color); +Construct a Rgbw64Color using RgbwColor, converting the R,G,B, and W values. +> * _color_ - a RgbwColor object. + +### Rgbw64Color(HslColor color); +Construct a Rgbw64Color using HslColor, converting the Hsl to Rgbw +> * _color_ - a HslColor object. + +### Rgbw64Color(HsbColor color); +Construct a Rgbw64Color using HsbColor, converting the Hsb to Rgbw +> * _color_ - a HsbColor object. + +### Rgbw64Color() +Construct a Rgbw64Color that will have its values set in latter operations. +CAUTION: The R,G,B,W members are not initialized and may not be consistent until set. + +## Methods +### uint16_t CalculateBrightness(); +CalculateBrightness will calculate the overall brightness. +NOTE: For color objects with only W set, it will return W. For color objects with W set to zero this is a simple linear brightness. For color objects with values in W and another color component, the overall brightness is the brighter of the color components and the W. + +### RgbwColor Dim(uint16_t ratio); +Dim will return a new color that is blended to black with the given ratio. +NOTE: This is a simple linear change. +> * _ratio_ - (0-65535) where 65535 will return the original color and 0 will return black. + +### RgbwColor Brighten(uint16_t ratio); +Brighten will return a new color that is blended to white with the given ratio. +NOTE: This is a simple linear change. +> * _ratio_ - (0-65535) where 65535 will return the original color and 0 will return white. + +### void Darken(uint16_t delta); +Darken will adjust the color by the given delta toward black. +NOTE: This is a simple linear change. +> * _delta_ - (0-65535) the amount to dim the color by. + +### void Lighten(uint16_t delta); +Lighten will adjust the color by the given delta toward white. +NOTE: This is a simple linear change. If the color only has W value set, only W will be modified; otherwise only the R,G,B will be modified leaving W alone. +> * _delta_ - (0-65535) the amount to lighten the color by. + +### static Rgbw64Color LinearBlend(Rgbw64Color left, Rgbw64Color right, float progress); +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... +``` + Rgbw64Color results = Rgbw64Color::LinearBlend(Rgbw64Color(65535,0,0,0), Rgbw64Color(0,65535,0,10), 0.33f); +``` + +### static RgbwColor LinearBlend(RgbwColor left, RgbwColor right, uint8_t progress); +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... +``` + Rgbw64Color results = Rgbw64Color::LinearBlend(Rgbw64Color(65535,0,0,0), Rgbw64Color(0,65535,0,10), 85); +``` + +### static Rgbw64Color BilinearBlend(Rgbw64Color c00, Rgbw64Color c01, Rgbw64Color c10, Rgbw64Color 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 + +## Operators +### uint16_t operator[](size_t idx) +The index operator allows accessing the R, G, B, and W properties using an index. There are both read only and read write versions. +``` + uint16_t white = color[3]; +``` \ No newline at end of file