Fork of the espurna firmware for `mhsw` switches
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.

68 lines
1.9 KiB

  1. #if GARLAND_SUPPORT
  2. #include "../anim.h"
  3. #include "../color.h"
  4. #include "../palette.h"
  5. #define DUST_LENGTH 20
  6. //------------------------------------------------------------------------------
  7. class AnimPixieDust : public Anim {
  8. public:
  9. AnimPixieDust() : Anim("PixieDust") {
  10. }
  11. void SetupImpl() override {
  12. phase = 0;
  13. curColor = palette->getRndInterpColor();
  14. prevColor = palette->getRndInterpColor();
  15. inc = secureRandom(2) * 2 - 1;
  16. if (inc > 0) {
  17. phase = -DUST_LENGTH / 2;
  18. } else {
  19. phase = numLeds + DUST_LENGTH / 2;
  20. }
  21. glowSetUp();
  22. }
  23. void Run() override {
  24. if (inc > 0) {
  25. for (int i = 0; i < numLeds; i++) {
  26. leds[i] = (i > phase) ? prevColor : curColor;
  27. glowForEachLed(i);
  28. }
  29. phase++;
  30. if (phase >= 4 * numLeds) {
  31. phase = -DUST_LENGTH / 2;
  32. prevColor = curColor;
  33. curColor = palette->getRndInterpColor();
  34. }
  35. } else {
  36. for (int i = 0; i < numLeds; i++) {
  37. leds[i] = (i < phase) ? prevColor : curColor;
  38. glowForEachLed(i);
  39. }
  40. phase--;
  41. if (phase <= -3 * numLeds) {
  42. phase = numLeds + DUST_LENGTH / 2;
  43. prevColor = curColor;
  44. curColor = palette->getContrastColor(prevColor);
  45. }
  46. }
  47. glowRun();
  48. for (int k = phase - DUST_LENGTH / 2; k < (phase + DUST_LENGTH / 2); k++) {
  49. if (k >= 0 && k < numLeds) {
  50. int mix = abs(k - phase) * 255 / DUST_LENGTH + ((int)rngb() - 125);
  51. if (mix < 0) {
  52. mix = 0;
  53. } else if (mix > 255) {
  54. mix = 255;
  55. }
  56. leds[k] = sparkleColor.interpolate(leds[k], (float)mix / 255);
  57. }
  58. }
  59. }
  60. };
  61. #endif // GARLAND_SUPPORT