summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index a8700cd..0873005 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,28 +11,42 @@
do { \
vp->x = x + map->tilewidth / 2 - vp->w / 2; \
vp->y = y + map->tileheight / 2 - vp->h / 2; \
- if (i % i_max < i_max / 4) { \
+ /* \
+ * See the following resources when computing realistic \
+ * daylight cycles: \
+ * * <https://en.wikipedia.org/wiki/Sunrise_equation> \
+ * * <http://www.esrl.noaa.gov/gmd/grad/solcalc/sunrise.html>\
+ */ \
+ if (i % i_max < i_max / 6 * 2) { \
+ /* 00:00 - 04:00 */ \
+ t_max = i_max / 6 * 2; \
pal_start = map->palettes[MAP_PALETTE_MORN] \
.palette->palette; \
pal_end = map->palettes[MAP_PALETTE_DAY] \
.palette->palette; \
- } else if (i % i_max < i_max / 4 * 2) { \
+ } else if (i % i_max < i_max / 6 * 4) { \
+ /* 04:00 - 12:00 */ \
+ t_max = i_max / 6 * 2; \
pal_start = map->palettes[MAP_PALETTE_DAY] \
.palette->palette; \
pal_end = map->palettes[MAP_PALETTE_EVE] \
.palette->palette; \
- } else if (i % i_max < i_max / 4 * 3) { \
+ } else if (i % i_max < i_max / 6 * 5) { \
+ /* 12:00 - 20:00 */ \
+ t_max = i_max / 6 * 1; \
pal_start = map->palettes[MAP_PALETTE_EVE] \
.palette->palette; \
pal_end = map->palettes[MAP_PALETTE_NIGHT] \
.palette->palette; \
} else { \
+ /* 04:00 - 12:00 */ \
+ t_max = i_max / 6 * 1; \
pal_start = map->palettes[MAP_PALETTE_NIGHT] \
.palette->palette; \
pal_end = map->palettes[MAP_PALETTE_MORN] \
.palette->palette; \
} \
- if (!cycle_palettes_cosine(i, i_max / 4, \
+ if (!cycle_palettes_cosine(i, t_max, \
pal_start, pal_end, pal)) { \
warn("Failed to cycle palettes"); \
} \
@@ -86,7 +100,7 @@ main(void)
/* Demo */
{
Uint32 start, end;
- int i, i_max;
+ int i, i_max, t_max;
int x, y;
SDL_Palette *pal_start, *pal_end;