ESPHome 2025.12.2
Loading...
Searching...
No Matches
color.cpp
Go to the documentation of this file.
2
3namespace esphome {
4
5// C++20 constinit ensures compile-time initialization (stored in ROM)
6constinit const Color Color::BLACK(0, 0, 0, 0);
7constinit const Color Color::WHITE(255, 255, 255, 255);
8
9Color Color::gradient(const Color &to_color, uint8_t amnt) {
10 Color new_color;
11 float amnt_f = float(amnt) / 255.0f;
12 new_color.r = amnt_f * (to_color.r - this->r) + this->r;
13 new_color.g = amnt_f * (to_color.g - this->g) + this->g;
14 new_color.b = amnt_f * (to_color.b - this->b) + this->b;
15 new_color.w = amnt_f * (to_color.w - this->w) + this->w;
16 return new_color;
17}
18
19Color Color::fade_to_white(uint8_t amnt) { return this->gradient(Color::WHITE, amnt); }
20
21Color Color::fade_to_black(uint8_t amnt) { return this->gradient(Color::BLACK, amnt); }
22
23} // namespace esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
Color fade_to_white(uint8_t amnt)
Definition color.cpp:19
uint8_t w
Definition color.h:42
uint8_t g
Definition color.h:34
Color fade_to_black(uint8_t amnt)
Definition color.cpp:21
Color gradient(const Color &to_color, uint8_t amnt)
Definition color.cpp:9
uint8_t b
Definition color.h:38
static const Color WHITE
Definition color.h:185
uint8_t r
Definition color.h:30
static const Color BLACK
Definition color.h:184