Skip to content

Commit

Permalink
candle animation
Browse files Browse the repository at this point in the history
  • Loading branch information
jiripraus committed Dec 23, 2020
1 parent 6f3f299 commit af582f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/floower-esp32/floower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ unsigned long Floower::touchStartedTime = 0;
unsigned long Floower::touchEndedTime = 0;
unsigned long Floower::lastTouchTime = 0;

const RgbColor candleColor(178, 45, 0); // 36

Floower::Floower(Config *config) : config(config), animations(2), pixels(7, NEOPIXEL_PIN) {}

void Floower::init() {
Expand Down Expand Up @@ -294,7 +296,11 @@ void Floower::startAnimation(FloowerColorAnimation animation) {
animations.StartAnimation(1, 10000, [=](const AnimationParam& param){ pixelsRainbowAnimationUpdate(param); });
}
else if (animation == CANDLE) {
pixelsTargetColor = pixelsColor = RgbColor(255, 100, 0); // orange
pixelsTargetColor = pixelsColor = RgbColor(candleColor); // candle orange
for (uint8_t i = 0; i < 6; i++) {
candleOriginColors[i] = pixelsTargetColor;
candleTargetColors[i] = pixelsTargetColor;
}
animations.StartAnimation(1, 100, [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); });
}
}
Expand Down Expand Up @@ -323,13 +329,19 @@ void Floower::pixelsRainbowAnimationUpdate(const AnimationParam& param) {
}

void Floower::pixelsCandleAnimationUpdate(const AnimationParam& param) {
pixels.SetPixelColor(0, pixelsTargetColor);
for (uint8_t i = 0; i < 6; i++) {
pixels.SetPixelColor(i + 1, RgbColor::LinearBlend(candleOriginColors[i], candleTargetColors[i], param.progress));
}

if (param.state == AnimationState_Completed) {
HsbColor hsbColor = HsbColor(pixelsTargetColor);
for (uint8_t i = 0; i < 7; i++) {
hsbColor.B = random(40, 100) / 100.0;
pixels.SetPixelColor(i, hsbColor);
HsbColor candleHsbColor = HsbColor(candleColor);
for (uint8_t i = 0; i < 6; i++) {
candleHsbColor.B = random(20, 100) / 100.0;
candleOriginColors[i] = candleTargetColors[i];
candleTargetColors[i] = RgbColor(candleHsbColor);
}
animations.StartAnimation(param.index, random(20, 200), [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); });
animations.StartAnimation(param.index, random(10, 400), [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); });
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/floower-esp32/floower.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Floower {

// acty
unsigned long actyOffTime;

// animations
RgbColor candleOriginColors[6];
RgbColor candleTargetColors[6];
};

#endif

0 comments on commit af582f8

Please sign in to comment.