Candle gradients more natural now
This commit is contained in:
parent
a6fac3451b
commit
549bc3d673
|
@ -1,6 +1,7 @@
|
||||||
#include "SimpLedRGB.h"
|
#include "SimpLedRGB.h"
|
||||||
|
|
||||||
SimpLedRGB::SimpLedRGB(int pinRed, int pinGreen, int pinBlue) {
|
SimpLedRGB::SimpLedRGB(int pinRed, int pinGreen, int pinBlue)
|
||||||
|
{
|
||||||
this->pin_red = pinRed;
|
this->pin_red = pinRed;
|
||||||
this->pin_green = pinGreen;
|
this->pin_green = pinGreen;
|
||||||
this->pin_blue = pinBlue;
|
this->pin_blue = pinBlue;
|
||||||
|
@ -75,19 +76,29 @@ void SimpLedRGB::rainbowCycle(int cycleDurationMillis)
|
||||||
translateToColor(COLOR_RED, cycleDurationMillis);
|
translateToColor(COLOR_RED, cycleDurationMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpLedRGB::candle(const Color &color)
|
void SimpLedRGB::candle(const Color &color, float wind = 0.5)
|
||||||
{
|
{
|
||||||
float brightness = (float)random(300, 1000) / 1000.0;
|
int duration = random(250, 6000 - 5000 * wind);
|
||||||
int duration = random(100, 1000);
|
float intensity = (float)random(100 + 400 * wind, 300 + 600 * wind) / 1000.0;
|
||||||
|
|
||||||
translateToColor(
|
unsigned long start = millis();
|
||||||
{
|
unsigned long finish = start + duration;
|
||||||
color.red * brightness,
|
|
||||||
color.green * brightness,
|
float progress = 0.0;
|
||||||
color.blue * brightness
|
|
||||||
},
|
while (progress < 1.0) {
|
||||||
duration
|
progress = (float)(millis() - start) / (float)duration;
|
||||||
);
|
|
||||||
|
float brightness = (1.0 - intensity) + (1.0 + cos(PI * 2 * progress)) * 0.5 * intensity;
|
||||||
|
|
||||||
|
setColor(
|
||||||
|
{
|
||||||
|
color.red * brightness,
|
||||||
|
color.green * brightness,
|
||||||
|
color.blue * brightness,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpLedRGB::pulse(const Color &color, float timesPerSecond = 1.0, float amplitudeMin = 0.0, float amplitudeMax = 1.0)
|
void SimpLedRGB::pulse(const Color &color, float timesPerSecond = 1.0, float amplitudeMin = 0.0, float amplitudeMax = 1.0)
|
||||||
|
|
|
@ -39,7 +39,7 @@ class SimpLedRGB
|
||||||
|
|
||||||
void rainbowCycle(int cycleDurationMillis);
|
void rainbowCycle(int cycleDurationMillis);
|
||||||
|
|
||||||
void candle(const Color &color);
|
void candle(const Color &color, float wind = 0.5);
|
||||||
|
|
||||||
void pulse(const Color &color, float timesPerSecond = 1.0, float amplitudeMin = 0.0, float amplitudeMax = 1.0);
|
void pulse(const Color &color, float timesPerSecond = 1.0, float amplitudeMin = 0.0, float amplitudeMax = 1.0);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue