add a mixed clock app

master
MaBecker 2019-11-13 11:50:05 +01:00
parent 8b66eecd08
commit bf906e1469
5 changed files with 105 additions and 0 deletions

View File

@ -396,5 +396,17 @@
{"name":"-scolor","url":"show-color.js"},
{"name":"*scolor","url":"show-color-icon.js","evaluate":true}
]
},
{ "id": "mclock",
"name": "A mix of analog and digital Clock",
"icon": "clock-mixed.png",
"description": "Mixed AD Clock",
"tags": "mclock",
"type":"clock",
"storage": [
{"name":"+mclock","url":"clock-mixed.json"},
{"name":"-mclock","url":"clock-mixed.js"},
{"name":"*mclock","url":"clock-mixed-icon.js","evaluate":true}
]
}
]

1
apps/clock-mixed-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+AH4A/AH4ATiwAGFdYzlFp4xeFyYwZD49kxGs2fX6+z1mIsgxcDQtAxArCAA+zxFAGDAYFxAsJAAuIGCxcF1omHgEABI+sGCouERRIvJSgKTEFzovLGAJgRCIiMIF5ySGF57qMF5nXsgvORoggLF5yRPLyAvO6+IF6LsKF6JgEF5lkD5gvPYIiOaF6CQMBYesD5oAP1gvPXxpfDAQIAFYCILDJ5wvP64veACCPeAB6PQd4p9EQQ4MLd6GIF7uIF5YwDsgiNAY4vHsguLYBJfXXxiQKL66ONF4lAL7dAF5pgIF6y9DFxYvEi2sF6+sDwgvLGAryEACLsEFxrCGGCmzXh5gJSQYAPRgovQGA1kMR7qEFyQwHi2IGJWzxCLEFygwIMYOI1gzC2esxBbGFywxKABotXGCwuaGKQtdGZorjAH4A/AF4="))

86
apps/clock-mixed.js Normal file
View File

@ -0,0 +1,86 @@
/* jshint esversion: 6 */
(function() {
const Radius = { "center": 8, "hour": 78, "min": 95, "dots": 102 };
const Center = { "x": 120, "y": 132 };
function rotatePoint(x, y, d) {
rad = -1 * d / 180 * Math.PI;
var sin = Math.sin(rad);
var cos = Math.cos(rad);
xn = ((Center.x + x * cos - y * sin) + 0.5) | 0;
yn = ((Center.y + x * sin - y * cos) + 0.5) | 0;
p = [xn, yn];
return p;
}
function drawMixedClock() {
var date = new Date();
var dateArray = date.toString().split(" ");
var point = [];
var minute = date.getMinutes();
var hour = date.getHours();
var radius;
// draw date
g.setColor(0x7be0);
g.setFont("6x8", 2);
g.setFontAlign(-1, 0);
g.drawString(dateArray[0] + ' ', 4, 35, true);
g.drawString(' ' + dateArray[2], 4, 225, true);
g.setFontAlign(1, 0);
g.drawString(dateArray[1], 237, 35, true);
g.drawString(dateArray[3], 237, 225, true);
// draw hour and minute dots
g.setColor(0xFD20); // orange
for (i = 0; i < 60; i++) {
radius = (i % 5) ? 2 : 4;
point = rotatePoint(0, Radius.dots, i * 6);
g.fillCircle(point[0], point[1], radius);
}
// erase last minutes hand
g.setColor(0);
point = rotatePoint(0, Radius.min, (minute - 1) * 6);
g.drawLine(Center.x, Center.y, point[0], point[1]);
// erase last two hour hands
g.setColor(0);
p = rotatePoint(0, Radius.hour, hour % 12 * 30 + (minute - 2) / 2 | 0);
g.drawLine(Center.x, Center.y, p[0], p[1]);
point = rotatePoint(0, Radius.hour, hour % 12 * 30 + (minute - 1) / 2 | 0);
g.drawLine(Center.x, Center.y, point[0], point[1]);
// draw digital time
g.setFont("6x8", 3);
g.setColor(0x7be0);
g.setFontAlign(0, 0);
g.drawString(dateArray[4].substr(0, 5), 120, 180, true);
// draw new minute hand
point = rotatePoint(0, Radius.min, minute * 6);
g.setColor(0xFFFF);
g.drawLine(Center.x, Center.y, point[0], point[1]);
// draw new hour hand
point = rotatePoint(0, Radius.hour, hour % 12 * 30 + date.getMinutes() / 2 | 0);
g.setColor(0xFFFF);
g.drawLine(Center.x, Center.y, point[0], point[1]);
// draw center
g.setColor(0xFD20);
g.fillCircle(Center.x, Center.y, Radius.center);
}
Bangle.on('lcdPower', function(on) {
if (on) {
drawMixedClock();
drawWidgets();
}
});
g.clear();
setInterval(drawMixedClock, 5E3);
drawMixedClock();
})();

6
apps/clock-mixed.json Normal file
View File

@ -0,0 +1,6 @@
{
"name":"Mixed Clock","type":"clock",
"icon":"*mclock",
"src":"-mclock",
"sortorder":-10
}

BIN
apps/clock-mixed.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B