From 2afc217124883e8b11e22081497ede12d61e0d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Sun, 15 Mar 2026 18:29:36 +0800 Subject: [PATCH] Refactor Pixel Fractal effect (#26071) --- .../animations/pixel_fractal_anim.h | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/quantum/rgb_matrix/animations/pixel_fractal_anim.h b/quantum/rgb_matrix/animations/pixel_fractal_anim.h index bf5c22a64e4..05d899f6ec2 100644 --- a/quantum/rgb_matrix/animations/pixel_fractal_anim.h +++ b/quantum/rgb_matrix/animations/pixel_fractal_anim.h @@ -10,50 +10,43 @@ static bool PIXEL_FRACTAL(effect_params_t* params) { # if MATRIX_COLS < 2 # define MID_COL 1 # else -# define MID_COL MATRIX_COLS / 2 +# define MID_COL (MATRIX_COLS / 2) # endif static bool led[MATRIX_ROWS][MID_COL]; static uint32_t wait_timer = 0; - inline uint32_t interval(void) { - return 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); - } - if (params->init) { rgb_matrix_set_color_all(0, 0, 0); + memset(led, 0, sizeof(led)); } RGB_MATRIX_USE_LIMITS(led_min, led_max); if (g_rgb_timer > wait_timer) { rgb_t 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) { - rgb_t index_rgb = led[h][l] ? (rgb_t){rgb.r, rgb.g, rgb.b} : (rgb_t){0, 0, 0}; - if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][l]], params->flags)) { - rgb_matrix_set_color(g_led_config.matrix_co[h][l], index_rgb.r, index_rgb.g, index_rgb.b); + for (uint8_t row = 0; row < MATRIX_ROWS; ++row) { + // Light columns outward from center, mirroring each side + for (uint8_t col = 0; col < MID_COL; ++col) { + rgb_t index_rgb = led[row][col] ? rgb : (rgb_t){0, 0, 0}; + uint8_t l_idx = g_led_config.matrix_co[row][col]; + uint8_t r_idx = g_led_config.matrix_co[row][MATRIX_COLS - 1 - col]; + if (l_idx >= led_min && l_idx < led_max && HAS_ANY_FLAGS(g_led_config.flags[l_idx], params->flags)) { + rgb_matrix_set_color(l_idx, index_rgb.r, index_rgb.g, index_rgb.b); } - if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][MATRIX_COLS - 1 - l]], params->flags)) { - rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], index_rgb.r, index_rgb.g, index_rgb.b); + if (r_idx >= led_min && r_idx < led_max && HAS_ANY_FLAGS(g_led_config.flags[r_idx], params->flags)) { + rgb_matrix_set_color(r_idx, index_rgb.r, index_rgb.g, index_rgb.b); } - led[h][l] = led[h][l + 1]; } - - // Light both middle columns - rgb_t index_rgb = led[h][MID_COL - 1] ? (rgb_t){rgb.r, rgb.g, rgb.b} : (rgb_t){0, 0, 0}; - if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][MID_COL - 1]], params->flags)) { - rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], index_rgb.r, index_rgb.g, index_rgb.b); - } - if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][MATRIX_COLS - MID_COL]], params->flags)) { - rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], index_rgb.r, index_rgb.g, index_rgb.b); - } - - // Generate new random fractal column - led[h][MID_COL - 1] = (random8() & 3) ? false : true; } - wait_timer = g_rgb_timer + interval(); + // Advance state and reset timer only on the final LED range iteration + if (!rgb_matrix_check_finished_leds(led_max)) { + for (uint8_t row = 0; row < MATRIX_ROWS; ++row) { + memmove(led[row], led[row] + 1, (MID_COL - 1) * sizeof(bool)); + led[row][MID_COL - 1] = !(random8() & 3); + } + wait_timer = g_rgb_timer + 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); + } } return rgb_matrix_check_finished_leds(led_max);