summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorFlorian Didron <florian@111studio.jp>2018-09-25 11:32:23 +0900
committerJack Humbert <jack.humb@gmail.com>2018-09-26 21:16:09 -0400
commitc7ce0d21dc07e1154b6a40cd621eb2eef075483b (patch)
tree1da78c52a01ec3376ebe1381af8c723649efbb18 /quantum
parent96648a133de7f297157b7d447be59354c1200c09 (diff)
downloadqmk_firmware-c7ce0d21dc07e1154b6a40cd621eb2eef075483b.tar.gz
qmk_firmware-c7ce0d21dc07e1154b6a40cd621eb2eef075483b.zip
Moves animation calculation logic out of the for loops
Diffstat (limited to 'quantum')
-rw-r--r--quantum/rgb_matrix.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 8ad00c37dd..5fb59af8c0 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -438,10 +438,12 @@ void rgb_matrix_cycle_up_down(void) {
void rgb_matrix_dual_beacon(void) {
HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
RGB rgb;
- rgb_led led;
+ Point point;
+ double cos_value = cos(g_tick * PI / 128) / 32;
+ double sin_value = sin(g_tick * PI / 128) / 112;
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_rgb_leds[i];
- hsv.h = ((led.point.y - 32.0)* cos(g_tick * PI / 128) / 32 + (led.point.x - 112.0) * sin(g_tick * PI / 128) / (112)) * (180) + rgb_matrix_config.hue;
+ point = g_rgb_leds[i].point;
+ hsv.h = ((point.y - 32.0)* cos_value + (point.x - 112.0) * sin_value) * (180) + rgb_matrix_config.hue;
rgb = hsv_to_rgb( hsv );
rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
}
@@ -450,10 +452,12 @@ void rgb_matrix_dual_beacon(void) {
void rgb_matrix_rainbow_beacon(void) {
HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
RGB rgb;
- rgb_led led;
+ Point point;
+ double cos_value = cos(g_tick * PI / 128);
+ double sin_value = sin(g_tick * PI / 128);
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_rgb_leds[i];
- hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.y - 32.0)* cos(g_tick * PI / 128) + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.x - 112.0) * sin(g_tick * PI / 128) + rgb_matrix_config.hue;
+ point = g_rgb_leds[i].point;
+ hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.y - 32.0)* cos_value + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.x - 112.0) * sin_value + rgb_matrix_config.hue;
rgb = hsv_to_rgb( hsv );
rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
}
@@ -462,10 +466,12 @@ void rgb_matrix_rainbow_beacon(void) {
void rgb_matrix_rainbow_pinwheels(void) {
HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
RGB rgb;
- rgb_led led;
+ Point point;
+ double cos_value = cos(g_tick * PI / 128);
+ double sin_value = sin(g_tick * PI / 128);
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_rgb_leds[i];
- hsv.h = (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.y - 32.0)* cos(g_tick * PI / 128) + (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (66 - abs(led.point.x - 112.0)) * sin(g_tick * PI / 128) + rgb_matrix_config.hue;
+ point = g_rgb_leds[i].point;
+ hsv.h = (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.y - 32.0)* cos_value + (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (66 - abs(point.x - 112.0)) * sin_value + rgb_matrix_config.hue;
rgb = hsv_to_rgb( hsv );
rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
}
@@ -474,12 +480,14 @@ void rgb_matrix_rainbow_pinwheels(void) {
void rgb_matrix_rainbow_moving_chevron(void) {
HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val };
RGB rgb;
- rgb_led led;
+ Point point;
+ uint8_t r = 128;
+ double cos_value = cos(r * PI / 128);
+ double sin_value = sin(r * PI / 128);
+ double multiplier = (g_tick / 256.0 * 224);
for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
- led = g_rgb_leds[i];
- // uint8_t r = g_tick;
- uint8_t r = 128;
- hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * abs(led.point.y - 32.0)* sin(r * PI / 128) + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.x - (g_tick / 256.0 * 224)) * cos(r * PI / 128) + rgb_matrix_config.hue;
+ point = g_rgb_leds[i].point;
+ hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * abs(point.y - 32.0)* sin_value + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (point.x - multiplier) * cos_value + rgb_matrix_config.hue;
rgb = hsv_to_rgb( hsv );
rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b );
}