Bug fixes

Increased sun position resolution. Fixed various wrong offsets. Fixed sun positions for sun rise & set. Fixed sine line not drawing until the right screen edge. Simplified
master
g-rden 2023-10-08 10:09:06 +00:00 committed by GitHub
parent 5a54681954
commit a9cfd89466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 43 deletions

View File

@ -182,20 +182,20 @@ function drawSinuses () {
g.setColor(1, 1, 1); g.setColor(1, 1, 1);
let y = ypos(x); let y = ypos(x);
while (x < w) { // until drawn line touches right side of the screen
while ((x - sinStep / 2) < w) {
y2 = ypos(x + sinStep); y2 = ypos(x + sinStep);
g.drawLine(x, y, x + sinStep, y2); // both x are offset by -sinStep/2
g.drawLine(x - sinStep / 2, y, x + sinStep / 2, y2);
y = y2; y = y2;
x += sinStep; // no need to draw all steps x += sinStep; // no need to draw all steps
} }
// sea level line // sea level line
const hh0 = sunrise.getHours(); const sl0 = seaLevel(sunrise.getHours());
const hh1 = sunset.getHours(); const sl1 = seaLevel(sunset.getHours());
const sl0 = seaLevel(hh0); sunRiseX = xfromTime(sunrise.getHours() + sunrise.getMinutes() / 60);
const sl1 = seaLevel(hh1); sunSetX = xfromTime(sunset.getHours() + sunset.getMinutes() / 60);
sunRiseX = xfromTime(hh0) + (r / 2);
sunSetX = xfromTime(hh1) + (r / 2);
g.setColor(0, 0.5, 1); g.setColor(0, 0.5, 1);
g.drawLine(0, sl0, w, sl1); g.drawLine(0, sl0, w, sl1);
g.drawLine(0, sl0 + 1, w, sl1 + 1); g.drawLine(0, sl0 + 1, w, sl1 + 1);
@ -221,19 +221,16 @@ const r = 10;
function drawGlow () { function drawGlow () {
const now = new Date(); const now = new Date();
if (frames < 1 && realTime) { if (frames < 1 && realTime) {
pos = xfromTime(now.getHours()); pos = xfromTime(now.getHours() + now.getMinutes() / 60);
} }
const rh = r / 2;
const x = pos; const x = pos;
const y = ypos(x); const y = ypos(x + sinStep / 2);
const r2 = 0;
g.setColor(0.2, 0.2, 0);
// wide glow
if (x > sunRiseX && x < sunSetX) { if (x > sunRiseX && x < sunSetX) {
g.setColor(0.2, 0.2, 0);
g.fillCircle(x, y, r + 20); g.fillCircle(x, y, r + 20);
g.setColor(0.5, 0.5, 0); g.setColor(0.5, 0.5, 0);
// wide glow
} else {
g.setColor(0.2, 0.2, 0);
} }
// smol glow // smol glow
g.fillCircle(x, y, r + 8); g.fillCircle(x, y, r + 8);
@ -254,20 +251,18 @@ function xfromTime (t) {
} }
function drawBall () { function drawBall () {
let x = pos;
const now = new Date(); const now = new Date();
if (frames < 1 && realTime) { if (frames < 1 && realTime) {
x = xfromTime(now.getHours()); pos = xfromTime(now.getHours() + now.getMinutes() / 60);
} }
const y = ypos(x); const x = pos;
const y = ypos(x + sinStep / 2);
// glow // glow
if (x < sunRiseX || x > sunSetX) { if (x > sunRiseX && x < sunSetX) {
g.setColor(0.5, 0.5, 0);
} else {
g.setColor(1, 1, 1); g.setColor(1, 1, 1);
} else {
g.setColor(0.5, 0.5, 0);
} }
const rh = r / 2;
g.fillCircle(x, y, r); g.fillCircle(x, y, r);
g.setColor(1, 1, 0); g.setColor(1, 1, 0);
g.drawCircle(x, y, r); g.drawCircle(x, y, r);
@ -275,44 +270,41 @@ function drawBall () {
function drawClock () { function drawClock () {
const now = new Date(); const now = new Date();
let curTime = ''; let hours = 0.0;
let fhours = 0.0; let mins = 0.0;
let fmins = 0.0;
let ypos = 32;
if (realTime) { if (realTime) {
fhours = now.getHours(); hours = now.getHours();
fmins = now.getMinutes(); mins = now.getMinutes();
} else { } else {
ypos = 32; hours = 24 * (pos / w);
fhours = 24 * (pos / w);
const nexth = 24 * 60 * (pos / w); const nexth = 24 * 60 * (pos / w);
fmins = 59 - ((24 * 60) - nexth) % 60; mins = 59 - ((24 * 60) - nexth) % 60;
// this prevents the displayed time to jump from 11:50 to 12:59 to 12:07 // this prevents the displayed time to jump from 11:50 to 12:59 to 12:07
if (fmins == 59) { if (mins == 59) {
fhours--; hours--;
} }
} }
const hours = ((fhours < 10) ? '0' : '') + (0 | fhours);
const mins = ((fmins < 10) ? '0' : '') + (0 | fmins); hours = ((hours < 10) ? '0' : '') + (0 | hours);
curTime = hours + ':' + mins; mins = ((mins < 10) ? '0' : '') + (0 | mins);
g.setFont('Vector', 30); g.setFont('Vector', 30);
g.setColor(realTime, 1, 1); g.setColor(realTime, 1, 1);
g.drawString(curTime, w / 1.9, ypos); g.drawString('' + hours + ':' + mins, w / 1.9, 32);
// day-month // day-month
if (realTime) { if (realTime) {
const mo = now.getMonth() + 1; const mo = now.getMonth() + 1;
const da = now.getDate(); const da = now.getDate();
const daymonth = '' + da + '/' + mo;
g.setFont('6x8', 2); g.setFont('6x8', 2);
g.drawString(daymonth, 5, 30); g.drawString('' + da + '/' + mo, 5, 30);
} }
} }
function renderScreen () { function renderScreen () {
const now = new Date();
g.setColor(0, 0, 0); g.setColor(0, 0, 0);
g.fillRect(0, 30, w, h); g.fillRect(0, 30, w, h);
realPos = xfromTime((new Date()).getHours()); realPos = xfromTime(now.getHours() + now.getMinutes() / 60);
g.setFontAlign(-1, -1, 0); g.setFontAlign(-1, -1, 0);
Bangle.drawWidgets(); Bangle.drawWidgets();
@ -329,7 +321,7 @@ Bangle.on('drag', function (tap, top) {
curPos = pos; curPos = pos;
initialAnimation(); initialAnimation();
} else { } else {
pos = tap.x - 5; pos = tap.x;
realTime = false; realTime = false;
} }
renderScreen(); renderScreen();