pixel_fractal_anim.h (2622B)
1 // Copyright (C) 2022 @filterpaper 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 // Inspired by 4x12 fractal from @GEIGEIGEIST 4 5 #ifdef ENABLE_RGB_MATRIX_PIXEL_FRACTAL 6 RGB_MATRIX_EFFECT(PIXEL_FRACTAL) 7 # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS 8 9 static bool PIXEL_FRACTAL(effect_params_t* params) { 10 # if MATRIX_COLS < 2 11 # define MID_COL 1 12 # else 13 # define MID_COL MATRIX_COLS / 2 14 # endif 15 static bool led[MATRIX_ROWS][MID_COL]; 16 static uint32_t wait_timer = 0; 17 18 inline uint32_t interval(void) { 19 return 3000 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16); 20 } 21 22 if (params->init) { 23 rgb_matrix_set_color_all(0, 0, 0); 24 } 25 26 RGB_MATRIX_USE_LIMITS(led_min, led_max); 27 28 if (g_rgb_timer > wait_timer) { 29 rgb_t rgb = rgb_matrix_hsv_to_rgb(rgb_matrix_config.hsv); 30 for (uint8_t h = 0; h < MATRIX_ROWS; ++h) { 31 // Light and copy columns outward 32 for (uint8_t l = 0; l < MID_COL - 1; ++l) { 33 rgb_t index_rgb = led[h][l] ? (rgb_t){rgb.r, rgb.g, rgb.b} : (rgb_t){0, 0, 0}; 34 if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][l]], params->flags)) { 35 rgb_matrix_set_color(g_led_config.matrix_co[h][l], index_rgb.r, index_rgb.g, index_rgb.b); 36 } 37 if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][MATRIX_COLS - 1 - l]], params->flags)) { 38 rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - 1 - l], index_rgb.r, index_rgb.g, index_rgb.b); 39 } 40 led[h][l] = led[h][l + 1]; 41 } 42 43 // Light both middle columns 44 rgb_t index_rgb = led[h][MID_COL - 1] ? (rgb_t){rgb.r, rgb.g, rgb.b} : (rgb_t){0, 0, 0}; 45 if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][MID_COL - 1]], params->flags)) { 46 rgb_matrix_set_color(g_led_config.matrix_co[h][MID_COL - 1], index_rgb.r, index_rgb.g, index_rgb.b); 47 } 48 if (HAS_ANY_FLAGS(g_led_config.flags[g_led_config.matrix_co[h][MATRIX_COLS - MID_COL]], params->flags)) { 49 rgb_matrix_set_color(g_led_config.matrix_co[h][MATRIX_COLS - MID_COL], index_rgb.r, index_rgb.g, index_rgb.b); 50 } 51 52 // Generate new random fractal column 53 led[h][MID_COL - 1] = (random8() & 3) ? false : true; 54 } 55 56 wait_timer = g_rgb_timer + interval(); 57 } 58 59 return rgb_matrix_check_finished_leds(led_max); 60 } 61 # endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS 62 #endif // ENABLE_RGB_MATRIX_PIXEL_FRACTAL