]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add a nicer sine based gradient for the LEDs
authorFred Sundvik <fsundvik@gmail.com>
Sun, 29 May 2016 15:27:32 +0000 (18:27 +0300)
committerFred Sundvik <fsundvik@gmail.com>
Sun, 29 May 2016 18:59:27 +0000 (21:59 +0300)
led_test.c
ugfx

index d53f0b7fb796f27d0e1d87da5498b670b19c7383..c2ea30b55ba4a0d7d38d5b2dc8d20362d53fc277 100644 (file)
@@ -89,14 +89,11 @@ static uint8_t crossfade_start_frame[NUM_ROWS][NUM_COLS];
 static uint8_t crossfade_end_frame[NUM_ROWS][NUM_COLS];
 
 static uint8_t compute_gradient_color(float t, float index, float num) {
-    const float target = t * (num - 1.0f);
-    const float half_num = num / 2.0f;
-    float d = fabs(index - target);
-    if (d > half_num) {
-        d = num - d;
-    }
-    d = 1.0f - (d / half_num);
-    return (uint8_t)(255.0f * d);
+    const float two_pi = 2.0f * PI;
+    float normalized_index = (1.0f - index / (num - 1)) * two_pi;
+    float x = t * two_pi + normalized_index;
+    float v = 0.5 * (cosf(x) + 1.0f);
+    return (uint8_t)(255.0f * v);
 }
 
 bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
diff --git a/ugfx b/ugfx
index 7d7eeef0ad0f1b28f4fb86ad931cb6774c7b9e81..dc5786acc246fb23503517647c386e43f1bfb247 160000 (submodule)
--- a/ugfx
+++ b/ugfx
@@ -1 +1 @@
-Subproject commit 7d7eeef0ad0f1b28f4fb86ad931cb6774c7b9e81
+Subproject commit dc5786acc246fb23503517647c386e43f1bfb247