summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-03-02 15:30:29 (EST)
committer P. J. McDermott <pjm@nac.net>2013-03-02 15:30:29 (EST)
commit8b50e6b67c77cfe254fa8d59e9018dc69603fc7a (patch)
tree2317ee0e8d1ac090802f279745e049f8fd220653 /src
parent48b9ee5ced72522a086146728f0772720bdfde7d (diff)
downloadoverworld-rpg-8b50e6b67c77cfe254fa8d59e9018dc69603fc7a.zip
overworld-rpg-8b50e6b67c77cfe254fa8d59e9018dc69603fc7a.tar.gz
overworld-rpg-8b50e6b67c77cfe254fa8d59e9018dc69603fc7a.tar.bz2
src/main.c: Use cosine curve for day-night cycle.
Diffstat (limited to 'src')
-rw-r--r--src/main.c30
1 files changed, 23 insertions, 7 deletions
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 <math.h>
#include <SDL.h>
#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");