raindrops_anim.h 1.2 KB

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