pixel_rain_anim.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright (C) 2021 @filterpaper
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifdef ENABLE_RGB_MATRIX_PIXEL_RAIN
  17. RGB_MATRIX_EFFECT(PIXEL_RAIN)
  18. # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
  19. static bool PIXEL_RAIN(effect_params_t* params) {
  20. static uint32_t wait_timer = 0;
  21. inline uint32_t interval(void) {
  22. return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16);
  23. }
  24. void rain_pixel(uint8_t i, effect_params_t * params, bool off) {
  25. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) {
  26. return;
  27. }
  28. if (off) {
  29. rgb_matrix_set_color(i, 0, 0, 0);
  30. } else {
  31. HSV hsv = {random8(), qadd8(random8() >> 1, 127), rgb_matrix_config.hsv.v};
  32. RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
  33. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
  34. }
  35. wait_timer = g_rgb_timer + interval();
  36. }
  37. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  38. if (g_rgb_timer > wait_timer) {
  39. rain_pixel(mod8(random8(), RGB_MATRIX_LED_COUNT), params, random8() & 2);
  40. }
  41. return rgb_matrix_check_finished_leds(led_max);
  42. }
  43. # endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
  44. #endif // ENABLE_RGB_MATRIX_PIXEL_RAIN