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.

66 lines
2.0 KiB

  1. #if GARLAND_SUPPORT
  2. #include <list>
  3. #include "../anim.h"
  4. #include "../color.h"
  5. #include "../palette.h"
  6. //------------------------------------------------------------------------------
  7. class AnimComets : public Anim {
  8. public:
  9. AnimComets() : Anim("Comets") {
  10. }
  11. void SetupImpl() override {
  12. comets.clear();
  13. for (int i = 0; i < 4; ++i)
  14. comets.emplace_back(palette, numLeds);
  15. }
  16. void Run() override {
  17. for (int i = 0; i < numLeds; ++i) leds[i] = 0;
  18. for (auto& c : comets) {
  19. int tail = c.head + c.len * -c.dir;
  20. // Check if Comet out of range and generate it again
  21. if ((c.head < 0 && tail < 0) || (c.head >= numLeds && tail >= numLeds)) {
  22. Comet new_comet(palette, numLeds);
  23. std::swap(c, new_comet);
  24. }
  25. for (int l = 0; l < c.len; ++l) {
  26. int p = c.head + l * -c.dir;
  27. if (p >= 0 && p < numLeds) {
  28. leds[p] = c.points[l];
  29. }
  30. }
  31. c.head = c.head + c.speed * c.dir;
  32. }
  33. }
  34. private:
  35. struct Comet {
  36. float head;
  37. int len = secureRandom(10, 20);
  38. float speed = ((float)secureRandom(4, 10)) / 10;
  39. Color color;
  40. int dir = 1;
  41. std::vector<Color> points;
  42. Comet(Palette* pal, uint16_t numLeds) : head(secureRandom(0, numLeds / 2)), color(pal->getRndInterpColor()), points(len) {
  43. // DEBUG_MSG_P(PSTR("[GARLAND] Comet created head = %d len = %d speed = %g cr = %d cg = %d cb = %d\n"), head, len, speed, color.r, color.g, color.b);
  44. if (secureRandom(10) > 5) {
  45. head = numLeds - head;
  46. dir = -1;
  47. }
  48. for (int i = 0; i < len; ++i) {
  49. points[i] = Color((byte)(color.r * (len - i) / len), (byte)(color.g * (len - i) / len), (byte)(color.b * (len - i) / len));
  50. }
  51. }
  52. };
  53. std::list<Comet> comets;
  54. };
  55. #endif // GARLAND_SUPPORT