mirror of
https://github.com/Makuna/NeoPixelBus.git
synced 2025-08-07 04:44:26 +02:00
Created Rgb16Color object API (markdown)
138
Rgb16Color-object-API.md
Normal file
138
Rgb16Color-object-API.md
Normal file
@@ -0,0 +1,138 @@
|
||||
Rgb16Color represents a color object that is represented by Red, Green, Blue component values using a 565 bit encoding with a total of 16 bits used.
|
||||
|
||||
## Properties
|
||||
There is a property that represent the component values Red, Green, and Blue in a 565 bit encoded value. It is best to use the property accessors to get and set the R, G, and B parts of this value.
|
||||
```
|
||||
uint16_t Color565
|
||||
```
|
||||
|
||||
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 = 255;
|
||||
```
|
||||
#### Count
|
||||
The number of color elements. Useful when accessing the elements using the [] operators.
|
||||
```
|
||||
const static size_t Count = 3;
|
||||
```
|
||||
## Constructors
|
||||
|
||||
### Rgb16Color(uint8_t r, uint8_t g, uint8_t b) :
|
||||
Constructs a Rgb16Color using Red, Green, and Blue color component values.
|
||||
> * r - value of Red component (0 - 255)
|
||||
> * g - value of Green component (0 - 255)
|
||||
> * b - value of Blue component (0 - 255)
|
||||
|
||||
### Rgb16Color(uint8_t brightness)
|
||||
Constructs a Rgb16Color using a single brightness value(0 - 255). This works well for creating gray tone colors.
|
||||
> * _brightness_ - brightness value where (0) = black, (128) = gray, (255) = white
|
||||
|
||||
### Rgb16Color(uint16_t color)
|
||||
Constructs a Rgb16Color using a single color value encoded in 565 model.
|
||||
> * _color_ - color encoded in 565 model
|
||||
|
||||
### Rgb16Color(RgbColor color);
|
||||
Construct a Rgb16Color using RgbColor, encoding the 8 bit elements into the single 565 16 bit value
|
||||
> * _color_ - an RgbColor object
|
||||
|
||||
### Rgb16Color(HtmlColor color);
|
||||
Construct a Rgb16Color using HtmlColor, converting the Html single value to Rgb component values
|
||||
> * _color_ - an HtmlColor object
|
||||
|
||||
### Rgb16Color(HslColor color);
|
||||
Construct a Rgb16Color using HslColor, converting the Hsl to Rgb
|
||||
> * _color_ - an HslColor object
|
||||
|
||||
### Rgb16Color(HsbColor color);
|
||||
Construct a Rgb16Color using HsbColor, converting the Hsb to Rgb
|
||||
> * _color_ - an HsbColor object
|
||||
|
||||
### Rgb16Color()
|
||||
Construct a Rgb16Color that will have its values set in latter operations.
|
||||
CAUTION: The Color565 member is not initialized and may not be consistent until set.
|
||||
|
||||
## Property Accessors
|
||||
### void setR(uint8_t r)
|
||||
Set the red value, encoding it into the single 16 bit value.
|
||||
> * _r_ - (0-255)
|
||||
|
||||
### uint8_t getR()
|
||||
get the red value, decoding it from the single 16 bit value
|
||||
|
||||
### void setG(uint8_t g)
|
||||
Set the green value, encoding it into the single 16 bit value.
|
||||
> * _g_ - (0-255)
|
||||
|
||||
### uint8_t getG()
|
||||
get the green value, decoding it from the single 16 bit value
|
||||
|
||||
### void setB(uint8_t b)
|
||||
Set the blue value, encoding it into the single 16 bit value.
|
||||
> * _b_ - (0-255)
|
||||
|
||||
### uint8_t getB()
|
||||
get the blue value, decoding it from the single 16 bit value
|
||||
|
||||
## Methods
|
||||
### uint8_t CalculateBrightness();
|
||||
CalculateBrightness will calculate the overall brightness.
|
||||
NOTE: This is a simple linear brightness
|
||||
|
||||
### Rgb16Color Dim(uint8_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-255) where 255 will return the original color and 0 will return black.
|
||||
|
||||
### Rgb16Color Brighten(uint8_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-255) where 255 will return the original color and 0 will return white.
|
||||
|
||||
### void Darken(uint8_t delta);
|
||||
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.
|
||||
|
||||
### void Lighten(uint8_t delta);
|
||||
Lighten will adjust the color by the given delta toward white.
|
||||
NOTE: This is a simple linear change.
|
||||
> * _delta_ - (0-255) the amount to lighten the color by.
|
||||
|
||||
### static Rgb16Color LinearBlend(Rgb16Color left, Rgb16Color 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...
|
||||
```
|
||||
Rgb16Color results = Rgb16Color::LinearBlend(Rgb16Color(255,0,0), Rgb16Color(0,255,0), 0.33f);
|
||||
```
|
||||
|
||||
### static Rgb16Color LinearBlend(Rgb16Color left, Rgb16Color 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...
|
||||
```
|
||||
Rgb16Color results = Rgb16Color::LinearBlend(Rgb16Color(255,0,0), Rgb16Color(0,255,0), 85);
|
||||
```
|
||||
|
||||
### static Rgb16Color BilinearBlend(Rgb16Color c00, Rgb16Color c01, Rgb16Color c10, Rgb16Color 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
|
||||
### uint8_t operator[](size_t idx)
|
||||
The index operator allows accessing the R, G, and B properties using an index. There are both read only and read write versions.
|
||||
```
|
||||
uint8_t green = color[1];
|
||||
```
|
Reference in New Issue
Block a user