aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix_animations/digital_rain_anim.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgb_matrix_animations/digital_rain_anim.h')
-rw-r--r--quantum/rgb_matrix_animations/digital_rain_anim.h120
1 files changed, 59 insertions, 61 deletions
diff --git a/quantum/rgb_matrix_animations/digital_rain_anim.h b/quantum/rgb_matrix_animations/digital_rain_anim.h
index 982399cbd..7a4a52db1 100644
--- a/quantum/rgb_matrix_animations/digital_rain_anim.h
+++ b/quantum/rgb_matrix_animations/digital_rain_anim.h
@@ -1,77 +1,75 @@
1#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) 1#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)
2RGB_MATRIX_EFFECT(DIGITAL_RAIN) 2RGB_MATRIX_EFFECT(DIGITAL_RAIN)
3#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS 3# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
4 4
5#ifndef RGB_DIGITAL_RAIN_DROPS 5# ifndef RGB_DIGITAL_RAIN_DROPS
6 // lower the number for denser effect/wider keyboard 6// lower the number for denser effect/wider keyboard
7 #define RGB_DIGITAL_RAIN_DROPS 24 7# define RGB_DIGITAL_RAIN_DROPS 24
8#endif 8# endif
9 9
10bool DIGITAL_RAIN(effect_params_t* params) { 10bool DIGITAL_RAIN(effect_params_t* params) {
11 // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain 11 // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
12 const uint8_t drop_ticks = 28; 12 const uint8_t drop_ticks = 28;
13 const uint8_t pure_green_intensity = 0xd0; 13 const uint8_t pure_green_intensity = 0xd0;
14 const uint8_t max_brightness_boost = 0xc0; 14 const uint8_t max_brightness_boost = 0xc0;
15 const uint8_t max_intensity = 0xff; 15 const uint8_t max_intensity = 0xff;
16 16
17 static uint8_t drop = 0; 17 static uint8_t drop = 0;
18 18
19 if (params->init) { 19 if (params->init) {
20 rgb_matrix_set_color_all(0, 0, 0); 20 rgb_matrix_set_color_all(0, 0, 0);
21 memset(rgb_frame_buffer, 0, sizeof(rgb_frame_buffer)); 21 memset(rgb_frame_buffer, 0, sizeof(rgb_frame_buffer));
22 drop = 0; 22 drop = 0;
23 } 23 }
24 24
25 for (uint8_t col = 0; col < MATRIX_COLS; col++) { 25 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
26 for (uint8_t row = 0; row < MATRIX_ROWS; row++) { 26 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
27 if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) { 27 if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
28 // top row, pixels have just fallen and we're 28 // top row, pixels have just fallen and we're
29 // making a new rain drop in this column 29 // making a new rain drop in this column
30 rgb_frame_buffer[row][col] = max_intensity; 30 rgb_frame_buffer[row][col] = max_intensity;
31 } 31 } else if (rgb_frame_buffer[row][col] > 0 && rgb_frame_buffer[row][col] < max_intensity) {
32 else if (rgb_frame_buffer[row][col] > 0 && rgb_frame_buffer[row][col] < max_intensity) { 32 // neither fully bright nor dark, decay it
33 // neither fully bright nor dark, decay it 33 rgb_frame_buffer[row][col]--;
34 rgb_frame_buffer[row][col]--; 34 }
35 } 35 // set the pixel colour
36 // set the pixel colour 36 uint8_t led[LED_HITS_TO_REMEMBER];
37 uint8_t led[LED_HITS_TO_REMEMBER]; 37 uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
38 uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
39 38
40 // TODO: multiple leds are supported mapped to the same row/column 39 // TODO: multiple leds are supported mapped to the same row/column
41 if (led_count > 0) { 40 if (led_count > 0) {
42 if (rgb_frame_buffer[row][col] > pure_green_intensity) { 41 if (rgb_frame_buffer[row][col] > pure_green_intensity) {
43 const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity)); 42 const uint8_t boost = (uint8_t)((uint16_t)max_brightness_boost * (rgb_frame_buffer[row][col] - pure_green_intensity) / (max_intensity - pure_green_intensity));
44 rgb_matrix_set_color(led[0], boost, max_intensity, boost); 43 rgb_matrix_set_color(led[0], boost, max_intensity, boost);
45 } 44 } else {
46 else { 45 const uint8_t green = (uint8_t)((uint16_t)max_intensity * rgb_frame_buffer[row][col] / pure_green_intensity);
47 const uint8_t green = (uint8_t) ((uint16_t) max_intensity * rgb_frame_buffer[row][col] / pure_green_intensity); 46 rgb_matrix_set_color(led[0], 0, green, 0);
48 rgb_matrix_set_color(led[0], 0, green, 0); 47 }
48 }
49 } 49 }
50 }
51 } 50 }
52 }
53 51
54 if (++drop > drop_ticks) { 52 if (++drop > drop_ticks) {
55 // reset drop timer 53 // reset drop timer
56 drop = 0; 54 drop = 0;
57 for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) { 55 for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
58 for (uint8_t col = 0; col < MATRIX_COLS; col++) { 56 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
59 // if ths is on the bottom row and bright allow decay 57 // if ths is on the bottom row and bright allow decay
60 if (row == MATRIX_ROWS - 1 && rgb_frame_buffer[row][col] == max_intensity) { 58 if (row == MATRIX_ROWS - 1 && rgb_frame_buffer[row][col] == max_intensity) {
61 rgb_frame_buffer[row][col]--; 59 rgb_frame_buffer[row][col]--;
62 } 60 }
63 // check if the pixel above is bright 61 // check if the pixel above is bright
64 if (rgb_frame_buffer[row - 1][col] == max_intensity) { 62 if (rgb_frame_buffer[row - 1][col] == max_intensity) {
65 // allow old bright pixel to decay 63 // allow old bright pixel to decay
66 rgb_frame_buffer[row - 1][col]--; 64 rgb_frame_buffer[row - 1][col]--;
67 // make this pixel bright 65 // make this pixel bright
68 rgb_frame_buffer[row][col] = max_intensity; 66 rgb_frame_buffer[row][col] = max_intensity;
67 }
68 }
69 } 69 }
70 }
71 } 70 }
72 } 71 return false;
73 return false;
74} 72}
75 73
76#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS 74# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
77#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN) 75#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_DIGITAL_RAIN)