Skip to content

Commit

Permalink
widmp: Fix variable definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nxdefiant committed Nov 30, 2023
1 parent e96ffad commit 68b1a36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions apps/widmp/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion apps/widmp/metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 8 additions & 7 deletions apps/widmp/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 68b1a36

Please sign in to comment.