Implement exact moon position based on phase (synodic month ~29.53d)
This commit is contained in:
1 parent
933ad5e19b
commit
bbff9b9874
1 file changed
+18
-2
+18
-2
@@ -960,6 +960,18 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({
|
||||
return ((hours / 24) * 360 + 90) * Math.PI / 180;
|
||||
}
|
||||
|
||||
// The Moon advances ~12.19° per day relative to the Sun (synodic month
|
||||
// ~29.53 days). Use SunCalc.getMoonIllumination().phase as the offset.
|
||||
// phase=0: New moon (same direction as Sun)
|
||||
// phase=0.5: Full moon (opposite the Sun)
|
||||
function moonAngleForTime(date) {
|
||||
var moonIllum = SunCalc.getMoonIllumination(date);
|
||||
var hours = date.getHours() + date.getMinutes() / 60;
|
||||
var hourAngle = (hours / 24) * 360 + 90;
|
||||
// Moon is roughly at hourAngle + phase * 360
|
||||
return ((hourAngle + moonIllum.phase * 360) % 360) * Math.PI / 180;
|
||||
}
|
||||
|
||||
function pointOnCircle(date, radius) {
|
||||
var angle = angleForTime(date);
|
||||
return {
|
||||
@@ -1181,7 +1193,11 @@ var effect = (VANTA.CLOUDS2 || VANTA.CLOUDS)({
|
||||
rpgSunCore.setAttribute('opacity', isDaytime ? '1' : '0.35');
|
||||
|
||||
// Moon position - based on current time on the orbit
|
||||
var moonP = pointOnCircle(now, MOON_ORBIT_RADIUS);
|
||||
var moonAngle = moonAngleForTime(now);
|
||||
var moonP = {
|
||||
x: CENTER_X + Math.cos(moonAngle) * MOON_ORBIT_RADIUS,
|
||||
y: CENTER_Y + Math.sin(moonAngle) * MOON_ORBIT_RADIUS
|
||||
};
|
||||
rpgMoon.setAttribute('transform', 'translate(' + moonP.x + ', ' + moonP.y + ')');
|
||||
|
||||
var moonVisible = false;
|
||||
@@ -1468,7 +1484,7 @@ window.weatherThemes = {
|
||||
if (moonTimes.set) {
|
||||
document.getElementById('dbg-moon-set-angle').textContent = (angleForTime(moonTimes.set) * 180 / Math.PI).toFixed(1) + '°';
|
||||
}
|
||||
document.getElementById('dbg-moon-now-angle').textContent = (angleForTime(now) * 180 / Math.PI).toFixed(1) + '°';
|
||||
document.getElementById('dbg-moon-now-angle').textContent = (moonAngleForTime(now) * 180 / Math.PI).toFixed(1) + '°';
|
||||
document.getElementById('dbg-theme').textContent = themeName || '-';
|
||||
document.getElementById('dbg-speed').textContent = currentThemeSpeed.toFixed(2);
|
||||
|
||||
|
||||
Reference in new issue
Block a user