diff options
-rw-r--r-- | src/main.c | 131 |
1 files changed, 97 insertions, 34 deletions
@@ -7,6 +7,42 @@ #include "viewport.h" #include "area.h" +#define CYCLE_LINEAR(t_max, r1, g1, b1, r2, g2, b2) \ + do { \ + x = (double) t / (double) t_max; \ + y_end = (i % 8) * 36; \ + y_start = y_end * r1; \ + y_end = y_end * r2; \ + colors[i].r = x * (y_end - y_start) + y_start; \ + y_end = (i % 64 / 8) * 36; \ + y_start = y_end * g1; \ + y_end = y_end * g2; \ + colors[i].g = x * (y_end - y_start) + y_start; \ + y_end = (i / 64) * 85; \ + y_start = y_end * b1; \ + y_end = y_end * b2; \ + colors[i].b = x * (y_end - y_start) + y_start; \ + } while (0) +#define CYCLE_COS(t_max, r1, g1, b1, r2, g2, b2) \ + do { \ + x = t * 3.14159 / t_max; \ + y_end = (i % 8) * 36; \ + y_start = y_end * r2; \ + y_end = y_end * r1; \ + colors[i].r = ((cos(x) + 1) / 2) * \ + (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) * \ + (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) * \ + (y_end - y_start) + y_start; \ + } while (0) + #define DEMO() \ do { \ vp->x = x + map->tilewidth / 2 - vp->w / 2; \ @@ -59,47 +95,74 @@ main(void) render_area_to_viewport(a, vp); { - Uint32 t; + Uint32 d, t; double x; int y_start, y_end; - for (t = 0; t <= 2880; t += 5) { - for (i = 0; i < 256; ++i) { - /* - * t => [0 .. INF] - * t[0 .. 1440] => x[0, 3.14159] - * x = (t % 1440) * 3.14159 / 720 - * y => [y_start, y_end] - * ((cos(x) + 1) / 2) => [0,1] - * y = ((cos(x) + 1) / 2) * - * (y_end - y_start) + y_start - */ - - x = t % 1440; - x = x * 3.14159 / 720; - - y_start = (i % 8) * 36; - y_end = y_start * 0.25; - colors[i].r = ((cos(x) + 1) / 2) * - (y_end - y_start) + y_start; - - y_start = (i % 64 / 8) * 36; - y_end = y_start * 0.25; - colors[i].g = ((cos(x) + 1) / 2) * - (y_end - y_start) + y_start; - - y_start = (i / 64) * 85; - y_end = y_start * 0.375; - colors[i].b = ((cos(x) + 1) / 2) * - (y_end - y_start) + y_start; + for (d = 0; d < 4; ++d) { + /* morn -> day */ + for (t = 0; t < 360; t += 1) { + for (i = 0; i < 256; ++i) { + CYCLE_COS(360, + 1.000, 0.875, 0.625, + 1.000, 1.000, 1.000 + ); + } + if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, + colors, 0, 256)) { + warn("Failed to set palette"); + } + SDL_Flip(vp->screen); + SDL_Delay(10); } - if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, colors, 0, 256)) { - warn("Failed to set palette"); + /* day -> eve */ + for (t = 0; t < 360; t += 1) { + for (i = 0; i < 256; ++i) { + CYCLE_COS(360, + 1.000, 1.000, 1.000, + 0.875, 0.625, 0.625 + ); + } + if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, + colors, 0, 256)) { + warn("Failed to set palette"); + } + SDL_Flip(vp->screen); + SDL_Delay(10); + } + /* eve -> night */ + for (t = 0; t < 360; t += 1) { + for (i = 0; i < 256; ++i) { + CYCLE_COS(360, + 0.875, 0.625, 0.625, + 0.250, 0.250, 0.500 + ); + } + if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, + colors, 0, 256)) { + warn("Failed to set palette"); + } + SDL_Flip(vp->screen); + SDL_Delay(10); + } + /* night -> morn */ + for (t = 0; t < 360; t += 1) { + for (i = 0; i < 256; ++i) { + CYCLE_COS(360, + 0.250, 0.250, 0.500, + 1.000, 0.875, 0.625 + ); + } + if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, + colors, 0, 256)) { + warn("Failed to set palette"); + } + SDL_Flip(vp->screen); + SDL_Delay(10); } - SDL_Flip(vp->screen); - SDL_Delay(10); } } + quit(0); /* Demo */ for (i = 0; i < 256; ++i) { |