pixel_rain_anim.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2022 @filterpaper
  2. // SPDX-License-Identifier: GPL-2.0+
  3. #ifdef ENABLE_RGB_MATRIX_PIXEL_RAIN
  4. RGB_MATRIX_EFFECT(PIXEL_RAIN)
  5. # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
  6. static bool PIXEL_RAIN(effect_params_t* params) {
  7. static uint8_t index = 0;
  8. static uint32_t timer = 0;
  9. if (params->iter == 0 && params->init) {
  10. index = random8_max(RGB_MATRIX_LED_COUNT);
  11. }
  12. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  13. if (timer < g_rgb_timer) { // Execute when the delay period has elapsed
  14. if (led_min <= index && index < led_max && HAS_ANY_FLAGS(g_led_config.flags[index], params->flags)) {
  15. // Assign a random HSV color to hsv with 50% probability, otherwise assign zeroed hsv
  16. hsv_t hsv = (random8() & 2) ? (hsv_t){0, 0, 0} : (hsv_t){random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v};
  17. rgb_t rgb = rgb_matrix_hsv_to_rgb(hsv);
  18. rgb_matrix_set_color(index, rgb.r, rgb.g, rgb.b);
  19. }
  20. if (!rgb_matrix_check_finished_leds(led_max)) {
  21. // In the final LED range, update the LED index and advance the timer for
  22. // the next cycle, scaling the delay between 256–2048 ms based on speed.
  23. index = random8_max(RGB_MATRIX_LED_COUNT);
  24. timer = g_rgb_timer + (2048 - scale16by8(1792, rgb_matrix_config.speed));
  25. }
  26. }
  27. return rgb_matrix_check_finished_leds(led_max);
  28. }
  29. # endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
  30. #endif // ENABLE_RGB_MATRIX_PIXEL_RAIN