exact coloring
parent
6dfa1f6526
commit
c7e0f7fe60
|
|
@ -36,36 +36,38 @@ function draw() {
|
|||
var d = new Date();
|
||||
var h = d.getHours();
|
||||
var m = d.getMinutes();
|
||||
var date = d.getDate();
|
||||
var s = d.getSeconds();
|
||||
var day = d.getDay();
|
||||
var month = d.getMonth();
|
||||
|
||||
var timeStr = wordFromHour(h);
|
||||
var dateStr = wordsFromDayMonth(day);
|
||||
|
||||
// draw time
|
||||
g.setBgColor(g.theme.bg);
|
||||
g.setColor(g.theme.fg);
|
||||
g.clear();
|
||||
g.setFontAlign(0, 0).setFont("Vector", 36);
|
||||
g.setFontAlign(-1, 0).setFont("Vector", 36);
|
||||
|
||||
// Calculate how much of the word should be colored based on minutes
|
||||
var coloredChars = Math.floor((timeStr.length * m) / 60);
|
||||
// Calculate exact progress through the hour (0 to 1)
|
||||
var progress = (m + (s / 60)) / 60;
|
||||
|
||||
// Draw the colored portion first
|
||||
if (coloredChars > 0) {
|
||||
// Get total width of the word and starting position
|
||||
var totalWidth = g.stringWidth(timeStr);
|
||||
var startX = x - totalWidth / 2;
|
||||
|
||||
// Calculate the exact position where the color should change
|
||||
var colorChangeX = startX + (totalWidth * progress);
|
||||
|
||||
// First draw the entire text in the uncolored version
|
||||
g.setColor(g.theme.fg2);
|
||||
g.drawString(timeStr, startX, y);
|
||||
|
||||
// Then draw the colored portion
|
||||
if (progress > 0) {
|
||||
g.setClipRect(startX, 0, colorChangeX, g.getHeight());
|
||||
g.setColor(g.theme.bg2);
|
||||
var coloredPart = timeStr.substring(0, coloredChars);
|
||||
var coloredWidth = g.stringWidth(coloredPart);
|
||||
g.drawString(coloredPart, x - (g.stringWidth(timeStr) / 2) + (coloredWidth / 2), y);
|
||||
}
|
||||
|
||||
// Draw the remaining portion
|
||||
if (coloredChars < timeStr.length) {
|
||||
g.setColor(g.theme.fg2);
|
||||
var remainingPart = timeStr.substring(coloredChars);
|
||||
var remainingWidth = g.stringWidth(remainingPart);
|
||||
g.drawString(remainingPart, x + (g.stringWidth(timeStr) / 2) - (remainingWidth / 2), y);
|
||||
g.drawString(timeStr, startX, y);
|
||||
// Reset clip rect to full screen
|
||||
g.setClipRect(0, 0, g.getWidth(), g.getHeight());
|
||||
}
|
||||
|
||||
// draw date at bottom of screen
|
||||
|
|
@ -73,7 +75,6 @@ function draw() {
|
|||
g.setFontAlign(0, 0).setFont("Vector", 20);
|
||||
g.drawString(g.wrapString(dateStr, g.getWidth()).join("\n"), x, g.getHeight() - 30);
|
||||
|
||||
// queue draw in one minute
|
||||
queueDraw();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "onewordclock",
|
||||
"name": "One Word Clock",
|
||||
"shortName": "One Word",
|
||||
"version": "0.7",
|
||||
"version": "0.8",
|
||||
"description": "A unique clock that displays a single evocative word for each hour of the day",
|
||||
"icon": "app.png",
|
||||
"tags": "clock",
|
||||
|
|
|
|||
Loading…
Reference in New Issue