diff options
-rw-r--r-- | src/main.c | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -25,21 +25,36 @@ } while (0) #define CYCLE_COS(t_max, r1, g1, b1, r2, g2, b2) \ do { \ - x = t * 3.14159 / t_max; \ + /* \ + * t = t \ + * t_max = t_max \ + * x = (t / t_max) * π \ + * for y in {r, g, b}: \ + * m = y_end - y_start \ + * x = x \ + * b = y_start \ + * y = m * ((cos(x) / 2) + 0.5) + b \ + */ \ + /* \ + * cos(x) => [-1 .. 1] \ + * (cos(x)/2)+0.5 => [0 .. 1] \ + * y => [y_start .. y_end] \ + */ \ + x = (double) t / (double) t_max * 3.14159; \ y_end = (i % 8) * 36; \ y_start = y_end * r2; \ y_end = y_end * r1; \ - colors[i].r = ((cos(x) + 1) / 2) * \ + colors[i].r = ((cos(x) / 2) + 0.5) * \ (y_end - y_start) + y_start; \ y_end = (i % 64 / 8) * 36; \ y_start = y_end * g2; \ y_end = y_end * g1; \ - colors[i].g = ((cos(x) + 1) / 2) * \ + colors[i].g = ((cos(x) / 2) + 0.5) * \ (y_end - y_start) + y_start; \ y_end = (i / 64) * 85; \ y_start = y_end * b2; \ y_end = y_end * b1; \ - colors[i].b = ((cos(x) + 1) / 2) * \ + colors[i].b = ((cos(x) / 2) + 0.5) * \ (y_end - y_start) + y_start; \ } while (0) |