ESPHome
2025.12.2
Loading...
Searching...
No Matches
esphome
core
color.cpp
Go to the documentation of this file.
1
#include "
esphome/core/color.h
"
2
3
namespace
esphome
{
4
5
// C++20 constinit ensures compile-time initialization (stored in ROM)
6
constinit
const
Color
Color::BLACK
(0, 0, 0, 0);
7
constinit
const
Color
Color::WHITE
(255, 255, 255, 255);
8
9
Color
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
19
Color
Color::fade_to_white
(uint8_t amnt) {
return
this->
gradient
(
Color::WHITE
, amnt); }
20
21
Color
Color::fade_to_black
(uint8_t amnt) {
return
this->
gradient
(
Color::BLACK
, amnt); }
22
23
}
// namespace esphome
color.h
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::Color
Definition
color.h:26
esphome::Color::fade_to_white
Color fade_to_white(uint8_t amnt)
Definition
color.cpp:19
esphome::Color::w
uint8_t w
Definition
color.h:42
esphome::Color::g
uint8_t g
Definition
color.h:34
esphome::Color::fade_to_black
Color fade_to_black(uint8_t amnt)
Definition
color.cpp:21
esphome::Color::gradient
Color gradient(const Color &to_color, uint8_t amnt)
Definition
color.cpp:9
esphome::Color::b
uint8_t b
Definition
color.h:38
esphome::Color::WHITE
static const Color WHITE
Definition
color.h:185
esphome::Color::r
uint8_t r
Definition
color.h:30
esphome::Color::BLACK
static const Color BLACK
Definition
color.h:184
Generated by
1.12.0