]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Fix compute_gradient_color
authorFred Sundvik <fsundvik@gmail.com>
Wed, 11 May 2016 19:06:26 +0000 (22:06 +0300)
committerFred Sundvik <fsundvik@gmail.com>
Wed, 11 May 2016 19:06:26 +0000 (22:06 +0300)
led_test.c

index ed65a0baa5fa5cdb55ee775fa000d6184ae7d928..d358ef81eb6f33637ccc4df2d02c0bf64fb064e9 100644 (file)
@@ -86,10 +86,13 @@ 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) {
-    float d = fabs(index - t);
-    if (d > num / 2.0f) {
+    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);
 }