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