diff --git a/apps/widmp/ChangeLog b/apps/widmp/ChangeLog index a51ac080a..eb5876a36 100644 --- a/apps/widmp/ChangeLog +++ b/apps/widmp/ChangeLog @@ -6,3 +6,4 @@ 0.06: Darkmode, custom colours, and fix a bug with acting on mylocation changes 0.07: Use default Bangle formatter for booleans 0.08: Better formula for the moon's phase +0.09: Fix variable definitions diff --git a/apps/widmp/metadata.json b/apps/widmp/metadata.json index 654b5a383..a334ec27e 100644 --- a/apps/widmp/metadata.json +++ b/apps/widmp/metadata.json @@ -1,7 +1,7 @@ { "id": "widmp", "name": "Moon Phase", - "version": "0.08", + "version": "0.09", "description": "Display the current moon phase in blueish (in light mode) or white (in dark mode) for both hemispheres. In the southern hemisphere the 'My Location' app is needed.", "icon": "widget.png", "type": "widget", diff --git a/apps/widmp/widget.js b/apps/widmp/widget.js index e5aa7fef2..89c072ca1 100644 --- a/apps/widmp/widget.js +++ b/apps/widmp/widget.js @@ -6,11 +6,11 @@ // https://github.com/deirdreobyrne/LunarPhase function moonPhase(sec) { - d = (4.847408287988257 + sec/406074.7465115577) % (2.0*Math.PI); - m = (6.245333801867877 + sec/5022682.784840698) % (2.0*Math.PI); - l = (4.456038755040014 + sec/378902.2499653011) % (2.0*Math.PI); - t = d+1.089809730923715e-01 * Math.sin(l)-3.614132757006379e-02 * Math.sin(m)+2.228248661252023e-02 * Math.sin(d+d-l)+1.353592753655652e-02 * Math.sin(d+d)+4.238560208195022e-03 * Math.sin(l+l)+1.961408105275610e-03 * Math.sin(d); - k = (1.0 - Math.cos(t))/2.0; + let d = (4.847408287988257 + sec/406074.7465115577) % (2.0*Math.PI); + let m = (6.245333801867877 + sec/5022682.784840698) % (2.0*Math.PI); + let l = (4.456038755040014 + sec/378902.2499653011) % (2.0*Math.PI); + let t = d+1.089809730923715e-01 * Math.sin(l)-3.614132757006379e-02 * Math.sin(m)+2.228248661252023e-02 * Math.sin(d+d-l)+1.353592753655652e-02 * Math.sin(d+d)+4.238560208195022e-03 * Math.sin(l+l)+1.961408105275610e-03 * Math.sin(d); + let k = (1.0 - Math.cos(t))/2.0; if ((t >= Math.PI) && (t < 2.0*Math.PI)) { k = -k; } @@ -19,7 +19,7 @@ function loadLocation() { // "mylocation.json" is created by the "My Location" app - location = require("Storage").readJSON("mylocation.json",1)||{"lat":50.1236,"lon":8.6553,"location":"Frankfurt"}; + let location = require("Storage").readJSON("mylocation.json",1)||{"lat":50.1236,"lon":8.6553,"location":"Frankfurt"}; southernHemisphere = (location.lat < 0); } @@ -63,12 +63,13 @@ function draw() { const CenterX = this.x + 12, CenterY = this.y + 12, Radius = 11; + let leftFactor, rightFactor; loadLocation(); g.reset().setColor(g.theme.bg); g.fillRect(CenterX - Radius, CenterY - Radius, CenterX + Radius, CenterY + Radius); - millis = (new Date()).getTime(); + let millis = (new Date()).getTime(); if ((millis - lastCalculated) >= 7000000) { // if it's more than 7,000 sec since last calculation, re-calculate! phase = moonPhase(millis/1000); lastCalculated = millis;