qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

flower_blooming_anim.h (2188B)


      1 /* Copyright 2023 HorrorTroll <https://github.com/HorrorTroll>
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #ifdef ENABLE_RGB_MATRIX_FLOWER_BLOOMING
     18 RGB_MATRIX_EFFECT(FLOWER_BLOOMING)
     19 #    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
     20 
     21 typedef hsv_t (*flower_blooming_f)(hsv_t hsv, uint8_t i, uint8_t time);
     22 
     23 bool effect_runner_bloom(effect_params_t* params, flower_blooming_f effect_func) {
     24     RGB_MATRIX_USE_LIMITS(led_min, led_max);
     25 
     26     uint8_t time = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed / 10, 1));
     27     for (uint8_t i = led_min; i < led_max; i++) {
     28         RGB_MATRIX_TEST_LED_FLAGS();
     29         if (g_led_config.point[i].y > k_rgb_matrix_center.y) {
     30             rgb_t bgr = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
     31             rgb_matrix_set_color(i, bgr.b, bgr.g, bgr.r);
     32         } else {
     33             rgb_t rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
     34             rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
     35         }
     36     }
     37     return rgb_matrix_check_finished_leds(led_max);
     38 }
     39 
     40 static hsv_t FLOWER_BLOOMING_math(hsv_t hsv, uint8_t i, uint8_t time) {
     41     if (g_led_config.point[i].y > k_rgb_matrix_center.y)
     42         hsv.h = g_led_config.point[i].x * 3 - g_led_config.point[i].y * 3 + time;
     43     else
     44         hsv.h = g_led_config.point[i].x * 3 - g_led_config.point[i].y * 3 - time;
     45     return hsv;
     46 }
     47 
     48 bool FLOWER_BLOOMING(effect_params_t* params) {
     49     return effect_runner_bloom(params, &FLOWER_BLOOMING_math);
     50 }
     51 
     52 #    endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
     53 #endif     // ENABLE_RGB_MATRIX_FLOWER_BLOOMING