widmp: Fix variable definitions

pull/3118/head
Erik Andresen 2023-11-30 22:20:48 +01:00
parent e96ffad55f
commit 68b1a36780
3 changed files with 10 additions and 8 deletions

View File

@ -6,3 +6,4 @@
0.06: Darkmode, custom colours, and fix a bug with acting on mylocation changes 0.06: Darkmode, custom colours, and fix a bug with acting on mylocation changes
0.07: Use default Bangle formatter for booleans 0.07: Use default Bangle formatter for booleans
0.08: Better formula for the moon's phase 0.08: Better formula for the moon's phase
0.09: Fix variable definitions

View File

@ -1,7 +1,7 @@
{ {
"id": "widmp", "id": "widmp",
"name": "Moon Phase", "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.", "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", "icon": "widget.png",
"type": "widget", "type": "widget",

View File

@ -6,11 +6,11 @@
// https://github.com/deirdreobyrne/LunarPhase // https://github.com/deirdreobyrne/LunarPhase
function moonPhase(sec) { function moonPhase(sec) {
d = (4.847408287988257 + sec/406074.7465115577) % (2.0*Math.PI); let d = (4.847408287988257 + sec/406074.7465115577) % (2.0*Math.PI);
m = (6.245333801867877 + sec/5022682.784840698) % (2.0*Math.PI); let m = (6.245333801867877 + sec/5022682.784840698) % (2.0*Math.PI);
l = (4.456038755040014 + sec/378902.2499653011) % (2.0*Math.PI); let 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); 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);
k = (1.0 - Math.cos(t))/2.0; let k = (1.0 - Math.cos(t))/2.0;
if ((t >= Math.PI) && (t < 2.0*Math.PI)) { if ((t >= Math.PI) && (t < 2.0*Math.PI)) {
k = -k; k = -k;
} }
@ -19,7 +19,7 @@
function loadLocation() { function loadLocation() {
// "mylocation.json" is created by the "My Location" app // "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); southernHemisphere = (location.lat < 0);
} }
@ -63,12 +63,13 @@
function draw() { function draw() {
const CenterX = this.x + 12, CenterY = this.y + 12, Radius = 11; const CenterX = this.x + 12, CenterY = this.y + 12, Radius = 11;
let leftFactor, rightFactor;
loadLocation(); loadLocation();
g.reset().setColor(g.theme.bg); g.reset().setColor(g.theme.bg);
g.fillRect(CenterX - Radius, CenterY - Radius, CenterX + Radius, CenterY + Radius); 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! if ((millis - lastCalculated) >= 7000000) { // if it's more than 7,000 sec since last calculation, re-calculate!
phase = moonPhase(millis/1000); phase = moonPhase(millis/1000);
lastCalculated = millis; lastCalculated = millis;