summaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix/animations
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgb_matrix/animations')
-rw-r--r--quantum/rgb_matrix/animations/pixel_fractal_anim.h78
-rw-r--r--quantum/rgb_matrix/animations/pixel_rain_anim.h14
-rw-r--r--quantum/rgb_matrix/animations/raindrops_anim.h15
-rw-r--r--quantum/rgb_matrix/animations/solid_reactive_anim.h3
-rw-r--r--quantum/rgb_matrix/animations/solid_reactive_cross.h3
-rw-r--r--quantum/rgb_matrix/animations/solid_reactive_nexus.h3
-rw-r--r--quantum/rgb_matrix/animations/solid_reactive_simple_anim.h3
-rw-r--r--quantum/rgb_matrix/animations/solid_reactive_wide.h3
-rw-r--r--quantum/rgb_matrix/animations/typing_heatmap_anim.h88
9 files changed, 104 insertions, 106 deletions
diff --git a/quantum/rgb_matrix/animations/pixel_fractal_anim.h b/quantum/rgb_matrix/animations/pixel_fractal_anim.h
index 906da1a48e..b26d5c4100 100644
--- a/quantum/rgb_matrix/animations/pixel_fractal_anim.h
+++ b/quantum/rgb_matrix/animations/pixel_fractal_anim.h
@@ -1,19 +1,5 @@
-/* Copyright (C) 2021 @filterpaper
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
+// Copyright (C) 2022 @filterpaper
+// SPDX-License-Identifier: GPL-2.0-or-later
// Inspired from 4x12 fractal created by @schwarzgrau
#ifdef ENABLE_RGB_MATRIX_PIXEL_FRACTAL
@@ -22,12 +8,8 @@ RGB_MATRIX_EFFECT(PIXEL_FRACTAL)
static bool PIXEL_FRACTAL(effect_params_t* params) {
# define MID_COL MATRIX_COLS / 2
- static bool led[MATRIX_ROWS][MATRIX_COLS];
-
+ static bool led[MATRIX_ROWS][MID_COL];
static uint32_t wait_timer = 0;
- if (wait_timer > g_rgb_timer) {
- return false;
- }
inline uint32_t interval(void) {
return 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16);
@@ -37,44 +19,40 @@ static bool PIXEL_FRACTAL(effect_params_t* params) {
rgb_matrix_set_color_all(0, 0, 0);
}
- RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv);
- for (uint8_t h = 0; h < MATRIX_ROWS; ++h) {
- for (uint8_t l = 0; l < MID_COL - 1; ++l) { // Light and move left columns outwards
- if (led[h][l]) {
- rgb_matrix_set_color(g_led_config.matrix_co[h][l], rgb.r, rgb.g, rgb.b);
- } else {
- rgb_matrix_set_color(g_led_config.matrix_co[h][l], 0, 0, 0);
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+
+ if (g_rgb_timer > wait_timer) {
+ RGB rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv);
+ for (uint8_t h = 0; h < MATRIX_ROWS; ++h) {
+ // Light and copy columns outward
+ for (uint8_t l = 0; l < MID_COL - 1; ++l) {
+ if (led[h][l]) {
+ rgb_matrix_set_color(g_led_config.matrix_co[h][l], rgb.r, rgb.g, rgb.b);
+ rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], rgb.r, rgb.g, rgb.b);
+ } else {
+ rgb_matrix_set_color(g_led_config.matrix_co[h][l], 0, 0, 0);
+ rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], 0, 0, 0);
+ }
+ led[h][l] = led[h][l + 1];
}
- led[h][l] = led[h][l + 1];
- }
- for (uint8_t r = MATRIX_COLS - 1; r > MID_COL; --r) { // Light and move right columns outwards
- if (led[h][r]) {
- rgb_matrix_set_color(g_led_config.matrix_co[h][r], rgb.r, rgb.g, rgb.b);
+ // Light both middle columns
+ if (led[h][MID_COL - 1]) {
+ rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], rgb.r, rgb.g, rgb.b);
+ rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], rgb.r, rgb.g, rgb.b);
} else {
- rgb_matrix_set_color(g_led_config.matrix_co[h][r], 0, 0, 0);
+ rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], 0, 0, 0);
+ rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], 0, 0, 0);
}
- led[h][r] = led[h][r - 1];
- }
- // Light both middle columns
- if (led[h][MID_COL]) {
- rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL], rgb.r, rgb.g, rgb.b);
- } else {
- rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL], 0, 0, 0);
- }
- if (led[h][MID_COL - 1]) {
- rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], rgb.r, rgb.g, rgb.b);
- } else {
- rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], 0, 0, 0);
+ // Generate new random fractal column
+ led[h][MID_COL - 1] = (random8() & 3) ? false : true;
}
- // Generate new random fractal columns
- led[h][MID_COL] = led[h][MID_COL - 1] = (random8() & 3) ? false : true;
+ wait_timer = g_rgb_timer + interval();
}
- wait_timer = g_rgb_timer + interval();
- return false;
+ return rgb_matrix_check_finished_leds(led_max);
}
# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
#endif // ENABLE_RGB_MATRIX_PIXEL_FRACTAL
diff --git a/quantum/rgb_matrix/animations/pixel_rain_anim.h b/quantum/rgb_matrix/animations/pixel_rain_anim.h
index 03488b43df..ce2528a26d 100644
--- a/quantum/rgb_matrix/animations/pixel_rain_anim.h
+++ b/quantum/rgb_matrix/animations/pixel_rain_anim.h
@@ -20,17 +20,14 @@ RGB_MATRIX_EFFECT(PIXEL_RAIN)
static bool PIXEL_RAIN(effect_params_t* params) {
static uint32_t wait_timer = 0;
- if (wait_timer > g_rgb_timer) {
- return false;
- }
inline uint32_t interval(void) {
return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16);
}
- bool rain_pixel(uint8_t i, effect_params_t * params, bool off) {
+ void rain_pixel(uint8_t i, effect_params_t * params, bool off) {
if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) {
- return true;
+ return;
}
if (off) {
rgb_matrix_set_color(i, 0, 0, 0);
@@ -40,10 +37,13 @@ static bool PIXEL_RAIN(effect_params_t* params) {
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
wait_timer = g_rgb_timer + interval();
- return false;
}
- return rain_pixel(mod8(random8(), DRIVER_LED_TOTAL), params, random8() & 2);
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
+ if (g_rgb_timer > wait_timer) {
+ rain_pixel(mod8(random8(), DRIVER_LED_TOTAL), params, random8() & 2);
+ }
+ return rgb_matrix_check_finished_leds(led_max);
}
# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
diff --git a/quantum/rgb_matrix/animations/raindrops_anim.h b/quantum/rgb_matrix/animations/raindrops_anim.h
index 2d4b53b7b0..a508e51183 100644
--- a/quantum/rgb_matrix/animations/raindrops_anim.h
+++ b/quantum/rgb_matrix/animations/raindrops_anim.h
@@ -14,23 +14,22 @@ static void raindrops_set_color(int i, effect_params_t* params) {
deltaH += 256;
}
- hsv.h = rgb_matrix_config.hsv.h + (deltaH * (rand() & 0x03));
+ hsv.h = rgb_matrix_config.hsv.h + (deltaH * (random8() & 0x03));
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
bool RAINDROPS(effect_params_t* params) {
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
if (!params->init) {
// Change one LED every tick, make sure speed is not 0
if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
- raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
+ raindrops_set_color(random8() % DRIVER_LED_TOTAL, params);
+ }
+ } else {
+ for (int i = led_min; i < led_max; i++) {
+ raindrops_set_color(i, params);
}
- return false;
- }
-
- RGB_MATRIX_USE_LIMITS(led_min, led_max);
- for (int i = led_min; i < led_max; i++) {
- raindrops_set_color(i, params);
}
return rgb_matrix_check_finished_leds(led_max);
}
diff --git a/quantum/rgb_matrix/animations/solid_reactive_anim.h b/quantum/rgb_matrix/animations/solid_reactive_anim.h
index d3a7ebbdf7..052bfb22fd 100644
--- a/quantum/rgb_matrix/animations/solid_reactive_anim.h
+++ b/quantum/rgb_matrix/animations/solid_reactive_anim.h
@@ -4,6 +4,9 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE)
# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
static HSV SOLID_REACTIVE_math(HSV hsv, uint16_t offset) {
+# ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE
+ hsv.h = scale16by8(g_rgb_timer, add8(rgb_matrix_config.speed, 1) >> 6);
+# endif
hsv.h += qsub8(130, offset);
return hsv;
}
diff --git a/quantum/rgb_matrix/animations/solid_reactive_cross.h b/quantum/rgb_matrix/animations/solid_reactive_cross.h
index 043a369b73..9e5703a0ea 100644
--- a/quantum/rgb_matrix/animations/solid_reactive_cross.h
+++ b/quantum/rgb_matrix/animations/solid_reactive_cross.h
@@ -19,6 +19,9 @@ static HSV SOLID_REACTIVE_CROSS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t di
dy = dy * 16 > 255 ? 255 : dy * 16;
effect += dx > dy ? dy : dx;
if (effect > 255) effect = 255;
+# ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE
+ hsv.h = scale16by8(g_rgb_timer, add8(rgb_matrix_config.speed, 1) >> 6);
+# endif
hsv.v = qadd8(hsv.v, 255 - effect);
return hsv;
}
diff --git a/quantum/rgb_matrix/animations/solid_reactive_nexus.h b/quantum/rgb_matrix/animations/solid_reactive_nexus.h
index 8d62a49fea..64f5064cf9 100644
--- a/quantum/rgb_matrix/animations/solid_reactive_nexus.h
+++ b/quantum/rgb_matrix/animations/solid_reactive_nexus.h
@@ -16,6 +16,9 @@ static HSV SOLID_REACTIVE_NEXUS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t di
if (effect > 255) effect = 255;
if (dist > 72) effect = 255;
if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255;
+# ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE
+ hsv.h = scale16by8(g_rgb_timer, add8(rgb_matrix_config.speed, 1) >> 6);
+# endif
hsv.v = qadd8(hsv.v, 255 - effect);
hsv.h = rgb_matrix_config.hsv.h + dy / 4;
return hsv;
diff --git a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h
index 0d0a424cf3..bd3ce0817d 100644
--- a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h
+++ b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h
@@ -4,6 +4,9 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE)
# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv, uint16_t offset) {
+# ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE
+ hsv.h = scale16by8(g_rgb_timer, add8(rgb_matrix_config.speed, 1) >> 6);
+# endif
hsv.v = scale8(255 - offset, hsv.v);
return hsv;
}
diff --git a/quantum/rgb_matrix/animations/solid_reactive_wide.h b/quantum/rgb_matrix/animations/solid_reactive_wide.h
index 7598796316..24fedc2020 100644
--- a/quantum/rgb_matrix/animations/solid_reactive_wide.h
+++ b/quantum/rgb_matrix/animations/solid_reactive_wide.h
@@ -14,6 +14,9 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_MULTIWIDE)
static HSV SOLID_REACTIVE_WIDE_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
uint16_t effect = tick + dist * 5;
if (effect > 255) effect = 255;
+# ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE
+ hsv.h = scale16by8(g_rgb_timer, add8(rgb_matrix_config.speed, 1) >> 6);
+# endif
hsv.v = qadd8(hsv.v, 255 - effect);
return hsv;
}
diff --git a/quantum/rgb_matrix/animations/typing_heatmap_anim.h b/quantum/rgb_matrix/animations/typing_heatmap_anim.h
index 4b17c4c3ed..a05c07760e 100644
--- a/quantum/rgb_matrix/animations/typing_heatmap_anim.h
+++ b/quantum/rgb_matrix/animations/typing_heatmap_anim.h
@@ -6,30 +6,41 @@ RGB_MATRIX_EFFECT(TYPING_HEATMAP)
# define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 25
# endif
+# ifndef RGB_MATRIX_TYPING_HEATMAP_SPREAD
+# define RGB_MATRIX_TYPING_HEATMAP_SPREAD 40
+# endif
+
+# ifndef RGB_MATRIX_TYPING_HEATMAP_AREA_LIMIT
+# define RGB_MATRIX_TYPING_HEATMAP_AREA_LIMIT 16
+# endif
void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) {
# ifdef RGB_MATRIX_TYPING_HEATMAP_SLIM
// Limit effect to pressed keys
g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32);
# else
- uint8_t m_row = row - 1;
- uint8_t p_row = row + 1;
- uint8_t m_col = col - 1;
- uint8_t p_col = col + 1;
-
- if (m_col < col) g_rgb_frame_buffer[row][m_col] = qadd8(g_rgb_frame_buffer[row][m_col], 16);
- g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32);
- if (p_col < MATRIX_COLS) g_rgb_frame_buffer[row][p_col] = qadd8(g_rgb_frame_buffer[row][p_col], 16);
-
- if (p_row < MATRIX_ROWS) {
- if (m_col < col) g_rgb_frame_buffer[p_row][m_col] = qadd8(g_rgb_frame_buffer[p_row][m_col], 13);
- g_rgb_frame_buffer[p_row][col] = qadd8(g_rgb_frame_buffer[p_row][col], 16);
- if (p_col < MATRIX_COLS) g_rgb_frame_buffer[p_row][p_col] = qadd8(g_rgb_frame_buffer[p_row][p_col], 13);
+ if (g_led_config.matrix_co[row][col] == NO_LED) { // skip as pressed key doesn't have an led position
+ return;
}
-
- if (m_row < row) {
- if (m_col < col) g_rgb_frame_buffer[m_row][m_col] = qadd8(g_rgb_frame_buffer[m_row][m_col], 13);
- g_rgb_frame_buffer[m_row][col] = qadd8(g_rgb_frame_buffer[m_row][col], 16);
- if (p_col < MATRIX_COLS) g_rgb_frame_buffer[m_row][p_col] = qadd8(g_rgb_frame_buffer[m_row][p_col], 13);
+ for (uint8_t i_row = 0; i_row < MATRIX_ROWS; i_row++) {
+ for (uint8_t i_col = 0; i_col < MATRIX_COLS; i_col++) {
+ if (g_led_config.matrix_co[i_row][i_col] == NO_LED) { // skip as target key doesn't have an led position
+ continue;
+ }
+ if (i_row == row && i_col == col) {
+ g_rgb_frame_buffer[row][col] = qadd8(g_rgb_frame_buffer[row][col], 32);
+ } else {
+# define LED_DISTANCE(led_a, led_b) sqrt16(((int8_t)(led_a.x - led_b.x) * (int8_t)(led_a.x - led_b.x)) + ((int8_t)(led_a.y - led_b.y) * (int8_t)(led_a.y - led_b.y)))
+ uint8_t distance = LED_DISTANCE(g_led_config.point[g_led_config.matrix_co[row][col]], g_led_config.point[g_led_config.matrix_co[i_row][i_col]]);
+# undef LED_DISTANCE
+ if (distance <= RGB_MATRIX_TYPING_HEATMAP_SPREAD) {
+ uint8_t amount = qsub8(RGB_MATRIX_TYPING_HEATMAP_SPREAD, distance);
+ if (amount > RGB_MATRIX_TYPING_HEATMAP_AREA_LIMIT) {
+ amount = RGB_MATRIX_TYPING_HEATMAP_AREA_LIMIT;
+ }
+ g_rgb_frame_buffer[i_row][i_col] = qadd8(g_rgb_frame_buffer[i_row][i_col], amount);
+ }
+ }
+ }
}
# endif
}
@@ -40,10 +51,7 @@ static uint16_t heatmap_decrease_timer;
static bool decrease_heatmap_values;
bool TYPING_HEATMAP(effect_params_t* params) {
- // Modified version of RGB_MATRIX_USE_LIMITS to work off of matrix row / col size
- uint8_t led_min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter;
- uint8_t led_max = led_min + RGB_MATRIX_LED_PROCESS_LIMIT;
- if (led_max > sizeof(g_rgb_frame_buffer)) led_max = sizeof(g_rgb_frame_buffer);
+ RGB_MATRIX_USE_LIMITS(led_min, led_max);
if (params->init) {
rgb_matrix_set_color_all(0, 0, 0);
@@ -63,28 +71,26 @@ bool TYPING_HEATMAP(effect_params_t* params) {
}
// Render heatmap & decrease
- for (int i = led_min; i < led_max; i++) {
- uint8_t row = i % MATRIX_ROWS;
- uint8_t col = i / MATRIX_ROWS;
- uint8_t val = g_rgb_frame_buffer[row][col];
-
- // set the pixel colour
- uint8_t led[LED_HITS_TO_REMEMBER];
- uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
- for (uint8_t j = 0; j < led_count; ++j) {
- if (!HAS_ANY_FLAGS(g_led_config.flags[led[j]], params->flags)) continue;
-
- HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)};
- RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
- rgb_matrix_set_color(led[j], rgb.r, rgb.g, rgb.b);
- }
-
- if (decrease_heatmap_values) {
- g_rgb_frame_buffer[row][col] = qsub8(val, 1);
+ uint8_t count = 0;
+ for (uint8_t row = 0; row < MATRIX_ROWS && count < RGB_MATRIX_LED_PROCESS_LIMIT; row++) {
+ for (uint8_t col = 0; col < MATRIX_COLS && RGB_MATRIX_LED_PROCESS_LIMIT; col++) {
+ if (g_led_config.matrix_co[row][col] >= led_min && g_led_config.matrix_co[row][col] < led_max) {
+ count++;
+ uint8_t val = g_rgb_frame_buffer[row][col];
+ if (!HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[row][col]], params->flags)) continue;
+
+ HSV hsv = {170 - qsub8(val, 85), rgb_matrix_config.hsv.s, scale8((qadd8(170, val) - 170) * 3, rgb_matrix_config.hsv.v)};
+ RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
+ rgb_matrix_set_color(g_led_config.matrix_co[row][col], rgb.r, rgb.g, rgb.b);
+
+ if (decrease_heatmap_values) {
+ g_rgb_frame_buffer[row][col] = qsub8(val, 1);
+ }
+ }
}
}
- return led_max < sizeof(g_rgb_frame_buffer);
+ return rgb_matrix_check_finished_leds(led_max);
}
# endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS