diff --git a/package/contents/code/lunacalc.js b/package/contents/code/lunacalc.js index 1c2d40c5af65e1b1c7ba22dc19423a119752192d..1c6f41d0de6efd551b89ae60615b8201023e58db 100644 --- a/package/contents/code/lunacalc.js +++ b/package/contents/code/lunacalc.js @@ -78,36 +78,37 @@ function reloadPhases() return getPhasesByLunation(lunation); } -function getCurrentPhase() // this function assumes that today is between phases[0] (last new moon) and phases[4] (next new moon) +function getCurrentPhase(interpolate) // this function assumes that today is between phases[0] (last new moon) and phases[4] (next new moon) { var oneDay = 1000 * 60 * 60 * 24; var today = new Date().getTime(); var phases = getTodayPhases(); - /* ------------------------------------------------------------------------- - // Estimate where the terminator is - base this on knowing where it - // is at each quarter, and interpolating. Cowboy maths. - // Determines how far into the current quarter we are, and uses - // the result to work out where the terminator is. This allows for - // the quarters being different sizes, rather than assuming they are - // each one quarter of the cycle time. - - var qnum = 0; - while (today > phases[qnum+1] && qnum < 3) { - qnum++; + var terminator; + if (interpolate) { + // Estimate where the terminator is - base this on knowing where it + // is at each quarter, and interpolating. Cowboy maths. + // Determines how far into the current quarter we are, and uses + // the result to work out where the terminator is. This allows for + // the quarters being different sizes, rather than assuming they are + // each one quarter of the cycle time. + + var qnum = 0; + while (today > phases[qnum+1] && qnum < 3) { + qnum++; + } + var quarterTime = phases[qnum+1].getTime() - phases[qnum].getTime(); + var sinceQuarter = today - phases[qnum].getTime(); + terminator = Math.floor(((sinceQuarter / quarterTime) + qnum) * 90); + } + else { + // Work out where the terminator is, 0..359 degrees. + // This assumes a constant rate for the month, which is unlikely + var cycleTime = phases[4].getTime() - phases[0].getTime(); + var sinceNew = today - phases[0].getTime(); + terminator = Math.floor((sinceNew / cycleTime) * 360); } - var quarterTime = phases[qnum+1].getTime() - phases[qnum].getTime(); - var sinceQuarter = today - phases[qnum].getTime(); - var terminator = Math.floor(((sinceQuarter / quarterTime) + qnum) * 90); - --------------------------------------------------------------------- */ - - // /* - // Work out where the terminator is, 0..359 degrees - var cycleTime = phases[4].getTime() - phases[0].getTime(); - var sinceNew = today - phases[0].getTime(); - var terminator = Math.floor((sinceNew / cycleTime) * 360); - // */ // Keep this in the range [0,360): if (terminator >= 360) { diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml index 6fab7c5e467ab143ed793e241b8ea625911c6a6c..ff0e18f8292d89ed0f5d3fdf6766988fa9f9b64b 100644 --- a/package/contents/ui/main.qml +++ b/package/contents/ui/main.qml @@ -70,7 +70,7 @@ Item { function updateDetails() { // set the correct image for the moon - currentPhase = LunaCalc.getCurrentPhase(); + currentPhase = LunaCalc.getCurrentPhase(true); lunaIcon.phaseNumber = 13; //currentPhase.number; lunaIcon.theta = currentPhase.terminator; lunaIcon.hemisphere = hemisphere;