aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix.c
diff options
context:
space:
mode:
authorDaniel Shields <daniel.shields@bcs.org>2018-09-03 08:26:53 +0100
committerJack Humbert <jack.humb@gmail.com>2018-09-26 12:21:49 -0400
commit4d5705ea6ceeb11cd2adc018644ec87c51af4e86 (patch)
tree3b04c29c6a14cea55ec6325e699723e135e0ffee /quantum/rgb_matrix.c
parent627ee050b491cc9d6ab57f90ac0f0779f6be47c9 (diff)
downloadqmk_firmware-4d5705ea6ceeb11cd2adc018644ec87c51af4e86.tar.gz
qmk_firmware-4d5705ea6ceeb11cd2adc018644ec87c51af4e86.zip
Add new RGB matrix effect digital rain aka The Matrix
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r--quantum/rgb_matrix.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 197bc1ac5..8ad00c37d 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -510,6 +510,69 @@ void rgb_matrix_jellybean_raindrops( bool initialize ) {
510 } 510 }
511} 511}
512 512
513void rgb_matrix_digital_rain( const bool initialize ) {
514 // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
515 const uint8_t drop_ticks = 28;
516 const uint8_t new_drop_probability = 24;
517 const uint8_t pure_green_intensity = 0xd0;
518 const uint8_t max_brightness_boost = 0xc0;
519 const uint8_t max_intensity = 0xff;
520
521 static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}};
522 static uint8_t drop = 0;
523
524 if (initialize) {
525 rgb_matrix_set_color_all(0, 0, 0);
526 memset(map, 0, sizeof map);
527 drop = 0;
528 }
529 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
530 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
531 if (row == 0 && drop == 0 && rand() < RAND_MAX / new_drop_probability) {
532 // top row, pixels have just fallen and we're
533 // making a new rain drop in this column
534 map[col][row] = max_intensity;
535 }
536 else if (map[col][row] > 0 && map[col][row] < max_intensity) {
537 // neither fully bright nor dark, decay it
538 map[col][row]--;
539 }
540 // set the pixel colour
541 uint8_t led, led_count;
542 map_row_column_to_led(row, col, &led, &led_count);
543
544 if (map[col][row] > pure_green_intensity) {
545 const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost
546 * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity));
547 rgb_matrix_set_color(led, boost, max_intensity, boost);
548 }
549 else {
550 const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity);
551 rgb_matrix_set_color(led, 0, green, 0);
552 }
553 }
554 }
555 if (++drop > drop_ticks) {
556 // reset drop timer
557 drop = 0;
558 for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
559 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
560 // if ths is on the bottom row and bright allow decay
561 if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) {
562 map[col][row]--;
563 }
564 // check if the pixel above is bright
565 if (map[col][row - 1] == max_intensity) {
566 // allow old bright pixel to decay
567 map[col][row - 1]--;
568 // make this pixel bright
569 map[col][row] = max_intensity;
570 }
571 }
572 }
573 }
574}
575
513void rgb_matrix_multisplash(void) { 576void rgb_matrix_multisplash(void) {
514 // if (g_any_key_hit < 0xFF) { 577 // if (g_any_key_hit < 0xFF) {
515 HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; 578 HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
@@ -685,6 +748,9 @@ void rgb_matrix_task(void) {
685 case RGB_MATRIX_JELLYBEAN_RAINDROPS: 748 case RGB_MATRIX_JELLYBEAN_RAINDROPS:
686 rgb_matrix_jellybean_raindrops( initialize ); 749 rgb_matrix_jellybean_raindrops( initialize );
687 break; 750 break;
751 case RGB_MATRIX_DIGITAL_RAIN:
752 rgb_matrix_digital_rain( initialize );
753 break;
688 #ifdef RGB_MATRIX_KEYPRESSES 754 #ifdef RGB_MATRIX_KEYPRESSES
689 case RGB_MATRIX_SOLID_REACTIVE: 755 case RGB_MATRIX_SOLID_REACTIVE:
690 rgb_matrix_solid_reactive(); 756 rgb_matrix_solid_reactive();