2025-11-16 12:29:19 +01:00
|
|
|
---
|
|
|
|
|
title: Clock
|
|
|
|
|
tags:
|
|
|
|
|
- demoExample
|
|
|
|
|
---
|
2026-02-21 12:58:31 +01:00
|
|
|
{% assign bodyClass = 'body_clock' -%}
|
|
|
|
|
{% layout 'hippie/simple.liquid' %}
|
2025-11-16 12:29:19 +01:00
|
|
|
|
|
|
|
|
{% block body %}
|
2026-02-25 23:35:29 +01:00
|
|
|
<header class="io pos_fix pin_top pin_right pin_left">
|
2026-02-26 00:40:54 +01:00
|
|
|
<button id="tglFormat" title="Toggle hour display">12-Stunden-Format</button>
|
|
|
|
|
<button id="tglSections" title="Toggle sections">Abschnitte</button>
|
2026-02-25 23:35:29 +01:00
|
|
|
</header>
|
2025-11-16 12:29:19 +01:00
|
|
|
<main>
|
2026-02-25 21:13:53 +01:00
|
|
|
<div class="wrap">
|
2026-02-25 23:35:29 +01:00
|
|
|
<canvas id="background" width="768" height="768"></canvas>
|
|
|
|
|
<canvas id="rings" width="768" height="768"></canvas>
|
2026-02-25 21:13:53 +01:00
|
|
|
</div>
|
2025-11-16 12:29:19 +01:00
|
|
|
</main>
|
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
|
|
{% block script %}
|
|
|
|
|
<script>
|
2026-02-25 21:13:53 +01:00
|
|
|
const canvasBkg = document.getElementById('background');
|
|
|
|
|
const ctxBkg = canvasBkg.getContext('2d');
|
|
|
|
|
const canvasRings = document.getElementById('rings');
|
|
|
|
|
const ctxRings = canvasRings.getContext('2d');
|
2026-02-26 19:30:30 +01:00
|
|
|
const wrap = document.querySelector('.wrap');
|
2026-02-25 21:13:53 +01:00
|
|
|
|
2025-11-16 12:57:43 +01:00
|
|
|
let is24HourFormat = true;
|
2026-02-26 00:40:54 +01:00
|
|
|
let drawSections = false;
|
2026-02-25 21:13:53 +01:00
|
|
|
let currentDate = new Date();
|
|
|
|
|
let currentMonth = currentDate.getMonth() + 1; // Get current month (0-11)
|
|
|
|
|
let daysInCurrentMonth = daysInMonth(currentMonth, currentDate.getFullYear());
|
|
|
|
|
|
|
|
|
|
const outerMargin = 8;
|
|
|
|
|
const ringWidth = 16;
|
|
|
|
|
const ringGap = 8;
|
2026-02-26 19:30:30 +01:00
|
|
|
let centerX = canvasRings.width / 2;
|
|
|
|
|
let centerY = canvasRings.height / 2;
|
|
|
|
|
let maxSize = (canvasRings.width / 2 - ringWidth / 2) - outerMargin;
|
|
|
|
|
|
|
|
|
|
resizeClock();
|
|
|
|
|
|
2026-02-25 21:13:53 +01:00
|
|
|
const rings = [
|
|
|
|
|
{
|
|
|
|
|
radius: maxSize,
|
|
|
|
|
color: 'black'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
radius: maxSize - (ringWidth + ringGap),
|
|
|
|
|
color: 'lightgrey'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
radius: maxSize - (ringWidth + ringGap) * 2,
|
|
|
|
|
color: 'white'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
radius: maxSize - (ringWidth + ringGap) * 3 - ringGap,
|
|
|
|
|
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-yellow').trim()
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-02-25 23:35:29 +01:00
|
|
|
radius: maxSize - (ringWidth + ringGap) * 4 - ringGap * 2,
|
2026-02-25 21:13:53 +01:00
|
|
|
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-orange').trim()
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-02-25 23:35:29 +01:00
|
|
|
radius: maxSize - (ringWidth + ringGap) * 5 - ringGap * 3,
|
2026-02-25 21:13:53 +01:00
|
|
|
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-pink').trim()
|
2026-02-25 23:35:29 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
radius: maxSize - (ringWidth + ringGap) * 6 - ringGap * 3,
|
|
|
|
|
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-purple').trim()
|
|
|
|
|
}
|
|
|
|
|
];
|
2026-02-26 00:40:54 +01:00
|
|
|
const groups = [
|
2026-02-25 23:35:29 +01:00
|
|
|
{
|
|
|
|
|
radius: rings[1].radius,
|
|
|
|
|
color: `rgba(0, 0, 0, .1)`,
|
|
|
|
|
width: 72
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
radius: rings[3].radius,
|
|
|
|
|
color: `rgba(0, 0, 0, .2)`,
|
|
|
|
|
width: ringWidth + ringGap
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
radius: rings[4].radius,
|
|
|
|
|
color: `rgba(0, 0, 0, .3)`,
|
|
|
|
|
width: ringWidth + ringGap
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
radius: maxSize - (ringWidth + ringGap) * 6 - ringGap - ringGap / 2,
|
|
|
|
|
color: `rgba(0, 0, 0, .4)`,
|
|
|
|
|
width: ringWidth * 2 + ringGap * 2
|
2026-02-25 21:13:53 +01:00
|
|
|
}
|
|
|
|
|
];
|
2026-02-26 00:40:54 +01:00
|
|
|
const sectionMarkerColor = `rgba(0, 0, 0, .2)`;
|
|
|
|
|
let sections = [
|
2026-02-25 21:13:53 +01:00
|
|
|
{
|
|
|
|
|
amount: 60,
|
|
|
|
|
radius: maxSize,
|
|
|
|
|
width: 1
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
amount: 60,
|
|
|
|
|
radius: rings[1].radius,
|
|
|
|
|
width: 1
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
amount: is24HourFormat ? 24 : 12,
|
|
|
|
|
radius: rings[2].radius,
|
|
|
|
|
width: 3
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
amount: 7,
|
|
|
|
|
radius: rings[3].radius,
|
|
|
|
|
width: 5
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
amount: daysInCurrentMonth,
|
|
|
|
|
radius: rings[4].radius,
|
|
|
|
|
width: 3
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-02-25 23:35:29 +01:00
|
|
|
amount: 365,
|
2026-02-25 21:13:53 +01:00
|
|
|
radius: rings[5].radius,
|
2026-02-25 23:35:29 +01:00
|
|
|
width: 1
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
amount: 12,
|
|
|
|
|
radius: rings[6].radius,
|
2026-02-25 21:13:53 +01:00
|
|
|
width: 3
|
|
|
|
|
}
|
|
|
|
|
];
|
2025-11-16 12:57:43 +01:00
|
|
|
|
2026-02-14 12:18:07 +01:00
|
|
|
document.getElementById('tglFormat').addEventListener('click', () => {
|
2025-11-16 12:57:43 +01:00
|
|
|
is24HourFormat = !is24HourFormat;
|
2026-02-14 12:18:07 +01:00
|
|
|
document.getElementById('tglFormat').textContent = is24HourFormat ? '12-Stunden-Format' : '24-Stunden-Format';
|
2026-02-26 00:40:54 +01:00
|
|
|
sections[2].amount = is24HourFormat ? 24 : 12;
|
|
|
|
|
drawBackground();
|
2025-11-16 12:57:43 +01:00
|
|
|
});
|
2025-11-16 12:29:19 +01:00
|
|
|
|
2026-02-26 00:40:54 +01:00
|
|
|
document.getElementById('tglSections').addEventListener('click', () => {
|
|
|
|
|
drawSections = !drawSections;
|
|
|
|
|
drawBackground();
|
2026-02-25 23:35:29 +01:00
|
|
|
});
|
2026-02-25 21:13:53 +01:00
|
|
|
|
2026-02-26 19:30:30 +01:00
|
|
|
// FIXME: Konstanten mit maxSize werden nicht verändert
|
|
|
|
|
window.addEventListener('resize', resizeClock);
|
2025-11-16 12:43:10 +01:00
|
|
|
|
2026-02-26 00:40:54 +01:00
|
|
|
drawBackground();
|
2026-02-25 21:13:53 +01:00
|
|
|
updateRings();
|
2026-02-26 00:40:54 +01:00
|
|
|
// TODO: TimeDisplay nutzen, ev. erweitern oder ähnliche Umsetzung anwenden
|
2026-02-25 21:13:53 +01:00
|
|
|
setInterval(updateRings, 1000);
|
2025-11-16 12:35:39 +01:00
|
|
|
|
2025-11-23 14:17:24 +01:00
|
|
|
function updateRings() {
|
2026-02-25 21:13:53 +01:00
|
|
|
currentDate = new Date();
|
2025-11-16 12:43:10 +01:00
|
|
|
const currentSeconds = currentDate.getSeconds();
|
|
|
|
|
const currentMinutes = currentDate.getMinutes();
|
|
|
|
|
const currentHours = currentDate.getHours();
|
2025-11-16 13:09:16 +01:00
|
|
|
const currentDayOfWeek = getNumericWeekday(currentDate);
|
2025-11-16 13:21:25 +01:00
|
|
|
const currentDayOfMonth = currentDate.getDate();
|
2026-02-25 23:35:29 +01:00
|
|
|
const currentDayOfYear = getNumericYearDay(currentDate);
|
2026-02-25 21:13:53 +01:00
|
|
|
currentMonth = currentDate.getMonth() + 1; // Get current month (0-11)
|
|
|
|
|
daysInCurrentMonth = daysInMonth(currentMonth, currentDate.getFullYear());
|
2025-11-16 12:43:10 +01:00
|
|
|
|
2025-11-23 14:17:24 +01:00
|
|
|
drawRings(
|
2025-11-16 13:21:25 +01:00
|
|
|
currentSeconds,
|
|
|
|
|
currentMinutes,
|
|
|
|
|
currentHours,
|
|
|
|
|
currentDayOfWeek,
|
|
|
|
|
currentDayOfMonth,
|
|
|
|
|
currentMonth,
|
2026-02-25 23:35:29 +01:00
|
|
|
currentDayOfYear,
|
2025-11-16 13:21:25 +01:00
|
|
|
daysInCurrentMonth
|
|
|
|
|
);
|
2025-11-16 12:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-16 13:09:16 +01:00
|
|
|
// TODO: Parameter für Wochenstart ergänzen
|
|
|
|
|
function getNumericWeekday(date) {
|
|
|
|
|
const weekday = date.getDay(); // 0 (Sunday) to 6 (Saturday)
|
|
|
|
|
return (weekday === 0) ? 7 : weekday;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 23:35:29 +01:00
|
|
|
function getNumericYearDay(date) {
|
|
|
|
|
const start = new Date(date.getFullYear(), 0, 0);
|
|
|
|
|
return Math.floor((date - start) / 86400000);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-16 13:21:25 +01:00
|
|
|
function daysInMonth(month, year) {
|
|
|
|
|
return new Date(year, month, 0).getDate();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 21:13:53 +01:00
|
|
|
function drawArc(value, maxValue, radius, strokeStyle) {
|
|
|
|
|
const startAngle = -0.5 * Math.PI; // Start at the top
|
|
|
|
|
const endAngle = startAngle + (2 * Math.PI * (value / maxValue));
|
|
|
|
|
|
|
|
|
|
ctxRings.lineWidth = 16;
|
|
|
|
|
ctxRings.strokeStyle = strokeStyle;
|
|
|
|
|
ctxRings.beginPath();
|
|
|
|
|
ctxRings.arc(centerX, centerY, radius, startAngle, endAngle, false);
|
|
|
|
|
ctxRings.stroke();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 23:35:29 +01:00
|
|
|
// TODO: Array rings nutzen
|
|
|
|
|
function drawRings(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, dayOfYear, daysInCurrentMonth) {
|
2026-02-25 21:13:53 +01:00
|
|
|
ctxRings.clearRect(0, 0, canvasRings.width, canvasRings.height);
|
|
|
|
|
|
|
|
|
|
drawArc(
|
|
|
|
|
(seconds === 0) ? 60 : seconds,
|
|
|
|
|
60,
|
|
|
|
|
rings[0].radius,
|
|
|
|
|
rings[0].color
|
|
|
|
|
);
|
|
|
|
|
drawArc(
|
|
|
|
|
(minutes === 0) ? 60 : minutes,
|
|
|
|
|
60,
|
|
|
|
|
rings[1].radius,
|
|
|
|
|
rings[1].color
|
|
|
|
|
);
|
|
|
|
|
drawArc(
|
2026-02-26 00:40:54 +01:00
|
|
|
// is24HourFormat ? ((hours === 0) ? 24 : hours) : hours % 12,
|
2026-02-25 21:13:53 +01:00
|
|
|
is24HourFormat ? hours : hours % 12,
|
|
|
|
|
is24HourFormat ? 24 : 12,
|
|
|
|
|
rings[2].radius,
|
|
|
|
|
rings[2].color
|
|
|
|
|
);
|
|
|
|
|
drawArc(dayOfWeek, 7, rings[3].radius, rings[3].color);
|
|
|
|
|
drawArc(dayOfMonth, daysInCurrentMonth, rings[4].radius, rings[4].color);
|
2026-02-25 23:35:29 +01:00
|
|
|
drawArc(dayOfYear, 365, rings[5].radius, rings[5].color);
|
|
|
|
|
drawArc(month, 12, rings[6].radius, rings[6].color);
|
2026-02-25 21:13:53 +01:00
|
|
|
}
|
2026-02-26 00:40:54 +01:00
|
|
|
|
|
|
|
|
function drawBackground() {
|
|
|
|
|
ctxBkg.clearRect(0, 0, canvasBkg.width, canvasBkg.height);
|
|
|
|
|
|
|
|
|
|
groups.forEach((section) => {
|
|
|
|
|
ctxBkg.strokeStyle = section.color;
|
|
|
|
|
ctxBkg.lineWidth = section.width;
|
|
|
|
|
ctxBkg.beginPath();
|
|
|
|
|
ctxBkg.arc(centerX, centerY, section.radius, 0, 2 * Math.PI);
|
|
|
|
|
ctxBkg.stroke();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (drawSections) {
|
|
|
|
|
sections.forEach((marker) => {
|
|
|
|
|
for (let i = 0; i < marker.amount; i++) {
|
|
|
|
|
const angle = (i * (360 / marker.amount) - 90) * (Math.PI / 180); // -90 to start at top
|
|
|
|
|
const outerRadius = marker.radius + ringWidth / 2;
|
|
|
|
|
const outerX = centerX + outerRadius * Math.cos(angle);
|
|
|
|
|
const outerY = centerY + outerRadius * Math.sin(angle);
|
|
|
|
|
const innerRadius = marker.radius - ringWidth / 2;
|
|
|
|
|
const innerX = centerX + innerRadius * Math.cos(angle);
|
|
|
|
|
const innerY = centerY + innerRadius * Math.sin(angle);
|
|
|
|
|
|
|
|
|
|
ctxBkg.strokeStyle = sectionMarkerColor;
|
|
|
|
|
ctxBkg.lineWidth = marker.width;
|
|
|
|
|
ctxBkg.beginPath();
|
|
|
|
|
ctxBkg.moveTo(outerX, outerY);
|
|
|
|
|
ctxBkg.lineTo(innerX, innerY);
|
|
|
|
|
ctxBkg.stroke();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-26 19:30:30 +01:00
|
|
|
|
|
|
|
|
function resizeClock() {
|
|
|
|
|
const height = window.innerHeight;
|
|
|
|
|
const width = window.innerWidth;
|
|
|
|
|
const windowDimension = {
|
|
|
|
|
value: Math.min(height, width),
|
|
|
|
|
smaller: height < width ? 'height' : 'width'
|
|
|
|
|
};
|
|
|
|
|
const clockSize = Math.floor(windowDimension.value * 0.9);
|
|
|
|
|
|
|
|
|
|
canvasBkg.style.width = clockSize + 'px';
|
|
|
|
|
canvasBkg.style.height = clockSize + 'px';
|
|
|
|
|
canvasRings.style.width = clockSize + 'px';
|
|
|
|
|
canvasRings.style.height = clockSize + 'px';
|
|
|
|
|
canvasBkg.width = clockSize;
|
|
|
|
|
canvasBkg.height = clockSize;
|
|
|
|
|
canvasRings.width = clockSize;
|
|
|
|
|
canvasRings.height = clockSize;
|
|
|
|
|
|
|
|
|
|
centerX = canvasRings.width / 2;
|
|
|
|
|
centerY = canvasRings.height / 2;
|
|
|
|
|
maxSize = (canvasRings.width / 2 - ringWidth / 2) - outerMargin;
|
|
|
|
|
|
|
|
|
|
wrap.style.width = clockSize + 'px';
|
|
|
|
|
wrap.style.height = clockSize + 'px';
|
|
|
|
|
|
|
|
|
|
console.debug(windowDimension);
|
|
|
|
|
console.debug('Clock size: ', clockSize);
|
|
|
|
|
console.debug('Radius: ', maxSize);
|
|
|
|
|
}
|
2025-11-16 12:29:19 +01:00
|
|
|
</script>
|
|
|
|
|
{% endblock %}
|