Mirror of espurna firmware for wireless switches and more
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.3 KiB

  1. #if GARLAND_SUPPORT
  2. #include "../anim.h"
  3. #include "../color.h"
  4. #include "../palette.h"
  5. #define SPARK_PROB 3 //probability of spark when in idle plase
  6. //------------------------------------------------------------------------------
  7. class AnimSparkr : public Anim {
  8. public:
  9. AnimSparkr() : Anim("Sparkr") {
  10. }
  11. void SetupImpl() override {
  12. glowSetUp();
  13. phase = 0;
  14. curColor = palette->getRndInterpColor();
  15. prevColor = palette->getRndInterpColor();
  16. initSeq();
  17. shuffleSeq();
  18. }
  19. void Run() override {
  20. for (auto i = 0; i < numLeds; ++i) {
  21. byte pos = seq[i];
  22. leds[pos] = (i > phase) ? prevColor
  23. : (i == phase) ? sparkleColor
  24. : curColor;
  25. glowForEachLed(i);
  26. }
  27. glowRun();
  28. if (phase > numLeds) {
  29. if (secureRandom(SPARK_PROB) == 0) {
  30. int i = (int)rngb() * numLeds / 256;
  31. leds[i] = sparkleColor;
  32. }
  33. }
  34. phase++;
  35. if (phase > 2 * numLeds) {
  36. phase = 0;
  37. prevColor = curColor;
  38. curColor = palette->getContrastColor(prevColor);
  39. shuffleSeq();
  40. }
  41. }
  42. };
  43. #endif // GARLAND_SUPPORT