diff options
author | P. J. McDermott <pjm@nac.net> | 2013-03-04 02:03:44 (EST) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-03-04 02:03:44 (EST) |
commit | f9e339b9345b90621e6c2a585033ce20b3837570 (patch) | |
tree | 559efbd0fab717b32c87b47e11c385e7ee4b6b95 /src | |
parent | d41706737aa268903955dad9006326b26c106833 (diff) | |
download | overworld-rpg-f9e339b9345b90621e6c2a585033ce20b3837570.zip overworld-rpg-f9e339b9345b90621e6c2a585033ce20b3837570.tar.gz overworld-rpg-f9e339b9345b90621e6c2a585033ce20b3837570.tar.bz2 |
src/main.c: Tweak cosine palette cycling macro.
Diffstat (limited to 'src')
-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) |