Show real day progress based on sun position in debug panel
This commit is contained in:
1 parent
b898d923d6
commit
b4d1066670
1 file changed
+19
-3
+19
-3
@@ -842,6 +842,22 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({
|
|||||||
function updateClockAndEvents() {
|
function updateClockAndEvents() {
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
|
|
||||||
|
// Calculate real day progress based on sun position
|
||||||
|
// 0% = midnight, 50% = noon, 100% = next midnight
|
||||||
|
var sunTimes = SunCalc.getTimes(now, PASSAU_LAT, PASSAU_LON);
|
||||||
|
var sunrise = sunTimes.sunrise;
|
||||||
|
var sunset = sunTimes.sunset;
|
||||||
|
var realDayProgress;
|
||||||
|
if (now < sunrise) {
|
||||||
|
var prevSunset = new Date(sunset.getTime() - 24 * 3600 * 1000);
|
||||||
|
realDayProgress = (now.getTime() - prevSunset.getTime()) / (sunrise.getTime() - prevSunset.getTime());
|
||||||
|
} else if (now < sunset) {
|
||||||
|
realDayProgress = 0.5 + (now.getTime() - sunrise.getTime()) / (sunset.getTime() - sunrise.getTime()) * 0.5;
|
||||||
|
} else {
|
||||||
|
realDayProgress = 0.5 + (now.getTime() - sunset.getTime()) / (sunrise.getTime() + 24 * 3600 * 1000 - sunset.getTime()) * 0.5;
|
||||||
|
}
|
||||||
|
realDayProgress = Math.max(0, Math.min(1, realDayProgress));
|
||||||
|
|
||||||
// Real-time clock hands and digital
|
// Real-time clock hands and digital
|
||||||
var h = now.getHours();
|
var h = now.getHours();
|
||||||
var m = now.getMinutes();
|
var m = now.getMinutes();
|
||||||
@@ -1082,12 +1098,12 @@ var weatherThemes = {
|
|||||||
return (now.getTime() - startOfDay.getTime()) / 86400000;
|
return (now.getTime() - startOfDay.getTime()) / 86400000;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDebug(t, palette, vantaColors, themeName) {
|
function updateDebug(t, palette, vantaColors, themeName, realDayProgress) {
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
var hh = now.getHours(), mm = now.getMinutes(), ss = now.getSeconds();
|
var hh = now.getHours(), mm = now.getMinutes(), ss = now.getSeconds();
|
||||||
document.getElementById('dbg-time').textContent =
|
document.getElementById('dbg-time').textContent =
|
||||||
(hh < 10 ? '0' : '') + hh + ':' + (mm < 10 ? '0' : '') + mm + ':' + (ss < 10 ? '0' : '') + ss;
|
(hh < 10 ? '0' : '') + hh + ':' + (mm < 10 ? '0' : '') + mm + ':' + (ss < 10 ? '0' : '') + ss;
|
||||||
document.getElementById('dbg-day').textContent = (t * 100).toFixed(1) + '%';
|
document.getElementById('dbg-day').textContent = realDayProgress != null ? (realDayProgress * 100).toFixed(1) + '%' : (t * 100).toFixed(1) + '%';
|
||||||
document.getElementById('dbg-weather').textContent =
|
document.getElementById('dbg-weather').textContent =
|
||||||
currentWeatherCode + ' (' + (weatherThemes[themeName] ? themeName : '?') + ')';
|
currentWeatherCode + ' (' + (weatherThemes[themeName] ? themeName : '?') + ')';
|
||||||
document.getElementById('dbg-theme').textContent = themeName || '-';
|
document.getElementById('dbg-theme').textContent = themeName || '-';
|
||||||
@@ -1184,7 +1200,7 @@ var weatherThemes = {
|
|||||||
speed: currentThemeSpeed
|
speed: currentThemeSpeed
|
||||||
});
|
});
|
||||||
document.body.style.backgroundColor = '#' + ('00000' + c.sky.toString(16)).slice(-6);
|
document.body.style.backgroundColor = '#' + ('00000' + c.sky.toString(16)).slice(-6);
|
||||||
updateDebug(t, null, c, currentWeatherThemeName);
|
updateDebug(t, null, c, currentWeatherThemeName, realDayProgress);
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user