Update widget.js
parent
191c908a58
commit
916e1410f8
|
|
@ -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();
|
||||
} };
|
||||
|
|
|
|||
Loading…
Reference in New Issue