From 8b50e6b67c77cfe254fa8d59e9018dc69603fc7a Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 02 Mar 2013 15:30:29 -0500 Subject: src/main.c: Use cosine curve for day-night cycle. --- (limited to 'src') diff --git a/src/main.c b/src/main.c index d2f10f9..842a20c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,4 @@ +#include #include #include "init.h" #include "logging.h" @@ -61,14 +62,29 @@ main(void) render_area_to_viewport(a, vp); { float step; - for (step = 1.0; step >= 0.25; step -= 0.00390625) { + int y_start, y_end; + for (step = 0.0; step < 12.57; step += 0.006136) { for (i = 0; i < 256; ++i) { - colors[i].r = (i % 8) * 36; - colors[i].g = (i % 64 / 8) * 36; - colors[i].b = (i / 64) * 85; - colors[i].r *= step; - colors[i].g *= step; - colors[i].b *= step; + /* + * ((cos(x) + 1) / 2) => [0,1] + * y = ((cos(x) + 1) / 2) * + * (y_end - y_start) + y_start + */ + + y_start = (i % 8) * 36; + y_end = y_start / 4; + colors[i].r = ((cos(step) + 1) / 2) * + (y_end - y_start) + y_start; + + y_start = (i % 64 / 8) * 36; + y_end = y_start / 4; + colors[i].g = ((cos(step) + 1) / 2) * + (y_end - y_start) + y_start; + + y_start = (i / 64) * 85; + y_end = y_start / 4; + colors[i].b = ((cos(step) + 1) / 2) * + (y_end - y_start) + y_start; } if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, colors, 0, 256)) { warn("Failed to set palette"); -- cgit v0.9.1