Prettify and validate JS

master
MomentumV 2025-02-12 09:38:25 -05:00
parent bc88bf08e3
commit 1c02277bac
1 changed files with 149 additions and 136 deletions

View File

@ -22,14 +22,23 @@ var COL ={
stime: 2047 stime: 2047
}; };
const TAU = 2.0 * Math.PI; const TAU = 2.0 * Math.PI;
const MX=g.getWidth()/2,MY=24+3+RADII.arcMax; const MX = g.getWidth() / 2,
MY = 24 + 3 + RADII.arcMax;
const DAY_MILLIS = 86400000; const DAY_MILLIS = 86400000;
const M_POS = { x: MX, y: MY, r: RADII.moon }; const M_POS = { x: MX, y: MY, r: RADII.moon };
// images // images
const moon_texture = { width : 80, height : 80, bpp : 1,transparent:0, const moon_texture = {
width: 80,
height: 80,
bpp: 1,
transparent: 0,
buffer: require("heatshrink").decompress(atob("ABsRqAJHkEiBA0N0uq1AIEgNVqtRqoJEgUiAAQJEioTBAAIzEl2q12oxATECQdVioJD/eqne60UCHQoADoAJBgf+xWrFIOACYUFCYo8Cj/73f70er0ROHAANUBIM//3///q1WIFAV1qtXCggJB//7CYO6keikBOHKAUDCIInClSgCgonBu4TK1W73ShBMQxkCh5OC//uFIInBi91q5PFCYISC3er//iOwXVE41UCYf+9//9AnCJopVBqEv/+/3//E4P6kUgJw4nDKAP+14TB1Xoq4hBEwYFBqgnB3Wr3e737KB/QnIqp3B32OKAYTBE4Z4BAoYnBEoRSC0fyE5ITBJ4WuCYP4J4J3CeQQFClbvBJgOqn5kBnRPKTwJMB1B4B92qEgQACJ4JTBkYnBYwOilYsBO5NUhYmB9+qxGC9TxBEYTvFqki3Y8B1Uikei3+oionIgGrO4OqwGC9H/xATK1/7E4UAnU7kATIqEAl/uE4WA12u0ATJgSgB/+ikUgnW70EFCY9AgGDE4PowEAlWowEBCZJ4BneggUgkRSBCZEAgEKJoIEBgEIAYQOCKYcVBIMqJgIEBgQSCgAQBqiJDRQIOBEwYAEMgNRiITBqKKBCYJJBE4xQGMQIABlBPHHgInDHQQjEAQJTCHgbFEABg8EBg5SDCgxNDABI=")) buffer: require("heatshrink").decompress(atob("ABsRqAJHkEiBA0N0uq1AIEgNVqtRqoJEgUiAAQJEioTBAAIzEl2q12oxATECQdVioJD/eqne60UCHQoADoAJBgf+xWrFIOACYUFCYo8Cj/73f70er0ROHAANUBIM//3///q1WIFAV1qtXCggJB//7CYO6keikBOHKAUDCIInClSgCgonBu4TK1W73ShBMQxkCh5OC//uFIInBi91q5PFCYISC3er//iOwXVE41UCYf+9//9AnCJopVBqEv/+/3//E4P6kUgJw4nDKAP+14TB1Xoq4hBEwYFBqgnB3Wr3e737KB/QnIqp3B32OKAYTBE4Z4BAoYnBEoRSC0fyE5ITBJ4WuCYP4J4J3CeQQFClbvBJgOqn5kBnRPKTwJMB1B4B92qEgQACJ4JTBkYnBYwOilYsBO5NUhYmB9+qxGC9TxBEYTvFqki3Y8B1Uikei3+oionIgGrO4OqwGC9H/xATK1/7E4UAnU7kATIqEAl/uE4WA12u0ATJgSgB/+ikUgnW70EFCY9AgGDE4PowEAlWowEBCZJ4BneggUgkRSBCZEAgEKJoIEBgEIAYQOCKYcVBIMqJgIEBgQSCgAQBqiJDRQIOBEwYAEMgNRiITBqKKBCYJJBE4xQGMQIABlBPHHgInDHQQjEAQJTCHgbFEABg8EBg5SDCgxNDABI="))
}; };
const needle = { width: 23, height: 11, bpp:1, transparent:0, const needle = {
width: 23,
height: 11,
bpp: 1,
transparent: 0,
buffer: atob("///B///D///AAAPAAAHAAAHAAAcAADz///H//8P//wA=") buffer: atob("///B///D///AAAPAAAHAAAHAAAcAADz///H//8P//wA=")
}; };
@ -50,9 +59,9 @@ function drawMoon(shadowShape){
g.setColor(0, 0, 0).fillCircle(MX, MY, RADII.arcMax + 3); g.setColor(0, 0, 0).fillCircle(MX, MY, RADII.arcMax + 3);
g.setColor(COL.moon).fillCircle(MX, MY, RADII.moon); g.setColor(COL.moon).fillCircle(MX, MY, RADII.moon);
g.setColor(COL.txture).drawImage(moon_texture, MX, MY, { rotate: 0 }); g.setColor(COL.txture).drawImage(moon_texture, MX, MY, { rotate: 0 });
//later can set the rotation here to the parallacticAngle from getMoonPosition // TODO: can set the rotation here to the parallacticAngle from getMoonPosition
g.setColor(COL.shadow).fillPoly(shadowShape); g.setColor(COL.shadow).fillPoly(shadowShape);
//later set rotation of the fillPoly? parallactic-mp.angle I think. // TODO: set rotation of the fillPoly? parallactic-mp.angle I think.
// Use g.transformVertices to do the rotation // Use g.transformVertices to do the rotation
} }
@ -72,7 +81,7 @@ function drawDayRing(times){
g.setFontAlign(0, 1, 1).drawString(hhmm[1], MX + rm + 2, MY); g.setFontAlign(0, 1, 1).drawString(hhmm[1], MX + rm + 2, MY);
// draw dots // draw dots
let edges = []; let edges = [];
boolean isDay; let isDay = false;
let flag = false; let flag = false;
if (radT[1] > TAU) { if (radT[1] > TAU) {
edges = [radT[1] - TAU, radT[0]]; edges = [radT[1] - TAU, radT[0]];
@ -122,12 +131,15 @@ function drawHHMM(d) {
function moonShade(pos, mp) { function moonShade(pos, mp) {
pos = pos !== undefined ? pos : M_POS; pos = pos !== undefined ? pos : M_POS;
mp = mp !== undefined ? mp : SunCalc.getMoonIllumination(new Date()); mp = mp !== undefined ? mp : SunCalc.getMoonIllumination(new Date());
//position has x,y, r for the drawing, mp is from SunCalc Moon Illumination // pos has x,y, r for the drawing, mp is from SunCalc Moon Illumination
let k = mp.fraction; let k = mp.fraction;
// k is the percent along the equator of the terminator // k is the percent along the equator of the terminator
const pts = Math.min(pos.r >> 1, 32); const pts = Math.min(pos.r >> 1, 32);
// this gives r/2 pts on the way down and up, capped at 64 total for polyfill // this gives r/2 pts on the way down and up, capped at 64 total for polyfill
let a=[],b=[],s1=1,s2=0; let a = [],
b = [],
s1 = 1,
s2 = 0;
// scale s1 is 1 or -1 for fixed edge of the shadow; defined via case switches below // scale s1 is 1 or -1 for fixed edge of the shadow; defined via case switches below
// scale s2 factor for the moving edge of the shadow // scale s2 factor for the moving edge of the shadow
// need to do some computation to simplify for new/full moon if k 'close enough' to 0 or 1/-1 // need to do some computation to simplify for new/full moon if k 'close enough' to 0 or 1/-1
@ -157,7 +169,8 @@ function tToRad(date) {
function draw() { function draw() {
// work out how to display the current time // work out how to display the current time
var d = new Date(), a=tToRad(d); var d = new Date(),
a = tToRad(d);
var shape = moonShade(M_POS, SunCalc.getMoonIllumination(d)); var shape = moonShade(M_POS, SunCalc.getMoonIllumination(d));
var sTimes = SunCalc.getTimes(d, location.lat, location.lon); var sTimes = SunCalc.getTimes(d, location.lat, location.lon);
var daylight = [sTimes.sunrise, sTimes.sunset]; var daylight = [sTimes.sunrise, sTimes.sunset];
@ -167,7 +180,7 @@ function draw() {
drawDayRing(daylight); drawDayRing(daylight);
drawHHMM(d); drawHHMM(d);
// draw pointer // draw pointer
//Maybe later make this an overlay that can be removed?? -avoid drawing so much every minute/second // TODO: Maybe later make this an overlay that can be removed?? -avoid drawing so much every minute/second
g.setColor(COL.needle).drawImage(needle, MX + RADII.needle * Math.cos(a), MY + RADII.needle * Math.sin(a), { rotate: a }); g.setColor(COL.needle).drawImage(needle, MX + RADII.needle * Math.cos(a), MY + RADII.needle * Math.sin(a), { rotate: a });
} }