BangleApps/apps/multiclock/ana.face.js

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-06-23 08:27:36 +00:00
(() => {
function getFace(){
const p = Math.PI/2;
const PRad = Math.PI/180;
2021-11-01 17:46:50 +00:00
var cx = g.getWidth()/2;
var cy = 12+g.getHeight()/2;
var scale = (g.getHeight()-24)/(240-24);
scale = scale>=1 ? 1 : scale;
2020-06-23 08:27:36 +00:00
function seconds(angle, r) {
const a = angle*PRad;
2021-11-01 17:46:50 +00:00
const x = cx+Math.sin(a)*r;
const y = cy-Math.cos(a)*r;
2020-06-23 08:27:36 +00:00
if (angle % 90 == 0) {
2021-11-01 17:46:50 +00:00
g.setColor(g.theme.fg2);
2020-06-23 08:27:36 +00:00
g.fillRect(x-6,y-6,x+6,y+6);
} else if (angle % 30 == 0){
2021-11-01 17:46:50 +00:00
g.setColor(g.theme.fg);
2020-06-23 08:27:36 +00:00
g.fillRect(x-4,y-4,x+4,y+4);
} else {
2021-11-01 17:46:50 +00:00
g.setColor(g.theme.fg);
2020-06-23 08:27:36 +00:00
g.fillRect(x-1,y-1,x+1,y+1);
}
}
function hand(angle, r1,r2, r3) {
2021-11-01 17:46:50 +00:00
r1 = scale*r1; r2=scale*r2; r3 = scale*r3;
2020-06-23 08:27:36 +00:00
const a = angle*PRad;
g.fillPoly([
2021-11-01 17:46:50 +00:00
cx+Math.sin(a)*r1,
cy-Math.cos(a)*r1,
cx+Math.sin(a+p)*r3,
cy-Math.cos(a+p)*r3,
cx+Math.sin(a)*r2,
cy-Math.cos(a)*r2,
cx+Math.sin(a-p)*r3,
cy-Math.cos(a-p)*r3]);
2020-06-23 08:27:36 +00:00
}
var minuteDate;
var secondDate;
function onSecond() {
2021-11-01 17:46:50 +00:00
g.setColor(g.theme.bg);
2020-06-23 08:27:36 +00:00
hand(360*secondDate.getSeconds()/60, -5, 90, 3);
if (secondDate.getSeconds() === 0) {
hand(360*(minuteDate.getHours() + (minuteDate.getMinutes()/60))/12, -16, 60, 7);
hand(360*minuteDate.getMinutes()/60, -16, 86, 7);
minuteDate = new Date();
}
2021-11-01 17:46:50 +00:00
g.setColor(g.theme.fg);
2020-06-23 08:27:36 +00:00
hand(360*(minuteDate.getHours() + (minuteDate.getMinutes()/60))/12, -16, 60, 7);
hand(360*minuteDate.getMinutes()/60, -16, 86, 7);
2021-11-01 17:46:50 +00:00
g.setColor(g.theme.fg2);
2020-06-23 08:27:36 +00:00
secondDate = new Date();
hand(360*secondDate.getSeconds()/60, -5, 90, 3);
2021-11-01 17:46:50 +00:00
g.setColor(g.theme.bg);
g.fillCircle(cx,cy,2);
2020-06-23 08:27:36 +00:00
}
function drawAll() {
secondDate = minuteDate = new Date();
// draw seconds
g.setColor(1,1,1);
for (let i=0;i<60;i++)
2021-11-01 17:46:50 +00:00
seconds(360*i/60, 100*scale);
2020-06-23 08:27:36 +00:00
onSecond();
}
2021-11-01 17:46:50 +00:00
return {init:drawAll, tick:onSecond, tickpersec:true};
2020-06-23 08:27:36 +00:00
}
return getFace;
})();