raindrops_anim.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #ifndef DISABLE_RGB_MATRIX_RAINDROPS
  3. #include "rgb_matrix_types.h"
  4. extern rgb_counters_t g_rgb_counters;
  5. extern led_config_t g_led_config;
  6. extern rgb_config_t rgb_matrix_config;
  7. static void raindrops_set_color(int i, effect_params_t* params) {
  8. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
  9. HSV hsv = { 0 , rgb_matrix_config.sat, rgb_matrix_config.val };
  10. // Take the shortest path between hues
  11. int16_t deltaH = ((rgb_matrix_config.hue + 180) % 360 - rgb_matrix_config.hue) / 4;
  12. if (deltaH > 127) {
  13. deltaH -= 256;
  14. } else if (deltaH < -127) {
  15. deltaH += 256;
  16. }
  17. hsv.h = rgb_matrix_config.hue + (deltaH * (rand() & 0x03));
  18. RGB rgb = hsv_to_rgb(hsv);
  19. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
  20. }
  21. bool rgb_matrix_raindrops(effect_params_t* params) {
  22. if (!params->init) {
  23. // Change one LED every tick, make sure speed is not 0
  24. if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
  25. raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
  26. }
  27. return false;
  28. }
  29. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  30. for (int i = led_min; i < led_max; i++) {
  31. raindrops_set_color(i, params);
  32. }
  33. return led_max < DRIVER_LED_TOTAL;
  34. }
  35. #endif // DISABLE_RGB_MATRIX_RAINDROPS