Skip to content
Snippets Groups Projects
Commit 0f1e2a36 authored by dxtwjb's avatar dxtwjb
Browse files

Interpolate shadow position based on time of quarters

Previously assumed each quarter was 1/4 of the cycle. Which its not.
THis is not ideal either.
parent 2f3bf400
No related branches found
No related tags found
No related merge requests found
...@@ -78,36 +78,37 @@ function reloadPhases() ...@@ -78,36 +78,37 @@ function reloadPhases()
return getPhasesByLunation(lunation); 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 oneDay = 1000 * 60 * 60 * 24;
var today = new Date().getTime(); var today = new Date().getTime();
var phases = getTodayPhases(); var phases = getTodayPhases();
/* ------------------------------------------------------------------------- var terminator;
// Estimate where the terminator is - base this on knowing where it if (interpolate) {
// is at each quarter, and interpolating. Cowboy maths. // Estimate where the terminator is - base this on knowing where it
// Determines how far into the current quarter we are, and uses // is at each quarter, and interpolating. Cowboy maths.
// the result to work out where the terminator is. This allows for // Determines how far into the current quarter we are, and uses
// the quarters being different sizes, rather than assuming they are // the result to work out where the terminator is. This allows for
// each one quarter of the cycle time. // 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) { var qnum = 0;
qnum++; 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): // Keep this in the range [0,360):
if (terminator >= 360) { if (terminator >= 360) {
......
...@@ -70,7 +70,7 @@ Item { ...@@ -70,7 +70,7 @@ Item {
function updateDetails() { function updateDetails() {
// set the correct image for the moon // set the correct image for the moon
currentPhase = LunaCalc.getCurrentPhase(); currentPhase = LunaCalc.getCurrentPhase(true);
lunaIcon.phaseNumber = 13; //currentPhase.number; lunaIcon.phaseNumber = 13; //currentPhase.number;
lunaIcon.theta = currentPhase.terminator; lunaIcon.theta = currentPhase.terminator;
lunaIcon.hemisphere = hemisphere; lunaIcon.hemisphere = hemisphere;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment