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.

48 lines
1.2 KiB

  1. #if GARLAND_SUPPORT
  2. #include "../anim.h"
  3. #include "../color.h"
  4. #include "../palette.h"
  5. //------------------------------------------------------------------------------
  6. class AnimFly : public Anim {
  7. public:
  8. AnimFly() : Anim("Fly") {
  9. }
  10. void SetupImpl() override {
  11. //length of particle tail
  12. pos = secureRandom(2, 15);
  13. //probability of the tail
  14. inc = secureRandom(5, 15);
  15. if (secureRandom(10) > 5) {
  16. inc = -inc;
  17. }
  18. phase = 0;
  19. }
  20. void Run() override {
  21. byte launchpos;
  22. if (inc > 0) {
  23. launchpos = numLeds - 1;
  24. for (int i = 1; i < numLeds; i++) {
  25. leds[i - 1] = leds[i];
  26. }
  27. } else {
  28. launchpos = 0;
  29. for (int i = numLeds - 2; i >= 0; i--) {
  30. leds[i + 1] = leds[i];
  31. }
  32. }
  33. if (secureRandom(abs(inc)) == 0) {
  34. curColor = palette->getRndInterpColor();
  35. phase = pos;
  36. }
  37. leds[launchpos] = Color((int)curColor.r * phase / pos, (int)curColor.g * phase / pos, (int)curColor.b * phase / pos);
  38. if (phase > 0) phase--;
  39. }
  40. };
  41. #endif // GARLAND_SUPPORT