Update widget.js

master
Hilmar Strauch 2022-02-12 13:33:34 +01:00 committed by GitHub
parent 191c908a58
commit 916e1410f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -1,5 +1,6 @@
WIDGETS["widmoon"] = { area: "tr", width: 24, draw: function() {
const CenterX = this.x + 12, CenterY = this.y + 12, Radius = 11;
var southernHemisphere = false; // when in southern hemisphere, use the "My Location" App
const simulate = false; // simulate one month in one minute
const updateR = 1000; // update every x ms in simulation
@ -15,6 +16,12 @@ WIDGETS["widmoon"] = { area: "tr", width: 24, draw: function() {
return (mproz);
}
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"};
if (location.lat < 0) southernHemisphere = true;
}
// code source: github.com/rozek/banglejs-2-activities/blob/main/README.md#drawmoonphase
function drawMoonPhase (CenterX,CenterY, Radius, leftFactor,rightFactor) {
let x = Radius, y = 0, Error = Radius;
@ -42,10 +49,15 @@ WIDGETS["widmoon"] = { area: "tr", width: 24, draw: function() {
leftFactor = mproz * 4 - 1;
rightFactor = (1 - mproz) * 4 - 1;
if (mproz >= 0.5) leftFactor = 1; else rightFactor = 1;
if (true == southernHemisphere) {
var tmp=leftFactor; leftFactor=rightFactor; rightFactor=tmp;
}
drawMoonPhase(CenterX,CenterY, Radius, leftFactor,rightFactor);
if (simulate) setTimeout(updateWidget, updateR);
}
loadLocation();
updateWidget();
} };