Compare commits
No commits in common. "2f876217565048758370545b09db95981af00ff6" and "318af09d400e1a485b9c2ec42beeaf9b34a789ee" have entirely different histories.
2f87621756
...
318af09d40
4 changed files with 74 additions and 276 deletions
6
TODO.md
6
TODO.md
|
|
@ -16,10 +16,6 @@
|
||||||
- Change io stuff
|
- Change io stuff
|
||||||
- Find name for styled interactive elements
|
- Find name for styled interactive elements
|
||||||
- Find name for io module with nested class names
|
- Find name for io module with nested class names
|
||||||
- Change demo module
|
|
||||||
- Keep placeholder and demo stuff
|
|
||||||
- Move other things
|
|
||||||
- Prevent styles to be global
|
|
||||||
|
|
||||||
# Content
|
# Content
|
||||||
|
|
||||||
|
|
@ -137,3 +133,5 @@
|
||||||
- [ ] template
|
- [ ] template
|
||||||
- [ ] slot
|
- [ ] slot
|
||||||
- [ ] canvas
|
- [ ] canvas
|
||||||
|
- *Clock*
|
||||||
|
- Add overlays to better distinguish day, week and year
|
||||||
|
|
@ -7,162 +7,81 @@ tags:
|
||||||
{% layout 'hippie/simple.liquid' %}
|
{% layout 'hippie/simple.liquid' %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<header class="io pos_fix pin_top pin_right pin_left">
|
|
||||||
<button id="tglFormat" title="Toggle hour display">12-Stunden-Format</button>
|
|
||||||
<button id="tglSections" title="Toggle sections">Abschnitte</button>
|
|
||||||
</header>
|
|
||||||
<main>
|
<main>
|
||||||
<div class="wrap">
|
<canvas id="rings" width="512" height="512"></canvas>
|
||||||
<canvas id="background" width="768" height="768"></canvas>
|
<p>
|
||||||
<canvas id="rings" width="768" height="768"></canvas>
|
<button id="tglFormat">12-Stunden-Format</button>
|
||||||
</div>
|
</p>
|
||||||
</main>
|
</main>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script>
|
<script>
|
||||||
const canvasBkg = document.getElementById('background');
|
// Page script
|
||||||
const ctxBkg = canvasBkg.getContext('2d');
|
const canvas = document.getElementById('rings');
|
||||||
const canvasRings = document.getElementById('rings');
|
const ctx = canvas.getContext('2d');
|
||||||
const ctxRings = canvasRings.getContext('2d');
|
|
||||||
const wrap = document.querySelector('.wrap');
|
|
||||||
|
|
||||||
let is24HourFormat = true;
|
let is24HourFormat = true;
|
||||||
let drawSections = false;
|
const colorDayOfWeek = getComputedStyle(document.documentElement).getPropertyValue('--clock-color-yellow').trim();
|
||||||
let currentDate = new Date();
|
const colorDayOfMonth = getComputedStyle(document.documentElement).getPropertyValue('--clock-color-orange').trim();
|
||||||
let currentMonth = currentDate.getMonth() + 1; // Get current month (0-11)
|
const colorMonth = getComputedStyle(document.documentElement).getPropertyValue('--clock-color-pink').trim();
|
||||||
let daysInCurrentMonth = daysInMonth(currentMonth, currentDate.getFullYear());
|
|
||||||
|
|
||||||
const outerMargin = 8;
|
|
||||||
const ringWidth = 16;
|
|
||||||
const ringGap = 8;
|
|
||||||
let centerX = canvasRings.width / 2;
|
|
||||||
let centerY = canvasRings.height / 2;
|
|
||||||
let maxSize = (canvasRings.width / 2 - ringWidth / 2) - outerMargin;
|
|
||||||
|
|
||||||
resizeClock();
|
|
||||||
|
|
||||||
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()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
radius: maxSize - (ringWidth + ringGap) * 4 - ringGap * 2,
|
|
||||||
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-orange').trim()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
radius: maxSize - (ringWidth + ringGap) * 5 - ringGap * 3,
|
|
||||||
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-pink').trim()
|
|
||||||
},
|
|
||||||
{
|
|
||||||
radius: maxSize - (ringWidth + ringGap) * 6 - ringGap * 3,
|
|
||||||
color: getComputedStyle(document.documentElement).getPropertyValue('--clock-color-purple').trim()
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const groups = [
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const sectionMarkerColor = `rgba(0, 0, 0, .2)`;
|
|
||||||
let sections = [
|
|
||||||
{
|
|
||||||
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
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 365,
|
|
||||||
radius: rings[5].radius,
|
|
||||||
width: 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
amount: 12,
|
|
||||||
radius: rings[6].radius,
|
|
||||||
width: 3
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
document.getElementById('tglFormat').addEventListener('click', () => {
|
document.getElementById('tglFormat').addEventListener('click', () => {
|
||||||
is24HourFormat = !is24HourFormat;
|
is24HourFormat = !is24HourFormat;
|
||||||
document.getElementById('tglFormat').textContent = is24HourFormat ? '12-Stunden-Format' : '24-Stunden-Format';
|
document.getElementById('tglFormat').textContent = is24HourFormat ? '12-Stunden-Format' : '24-Stunden-Format';
|
||||||
sections[2].amount = is24HourFormat ? 24 : 12;
|
|
||||||
drawBackground();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('tglSections').addEventListener('click', () => {
|
function drawRings(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, daysInCurrentMonth) {
|
||||||
drawSections = !drawSections;
|
const centerX = canvas.width / 2;
|
||||||
drawBackground();
|
const centerY = canvas.height / 2;
|
||||||
});
|
const lineWidth = 16;
|
||||||
|
const lineGap = 8;
|
||||||
|
const maxSize = canvas.width / 2 - lineWidth;
|
||||||
|
|
||||||
// FIXME: Konstanten mit maxSize werden nicht verändert
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
window.addEventListener('resize', resizeClock);
|
|
||||||
|
|
||||||
drawBackground();
|
function drawArc(value, maxValue, radius, strokeStyle) {
|
||||||
updateRings();
|
const startAngle = -0.5 * Math.PI; // Start at the top
|
||||||
// TODO: TimeDisplay nutzen, ev. erweitern oder ähnliche Umsetzung anwenden
|
const endAngle = startAngle + (2 * Math.PI * (value / maxValue));
|
||||||
setInterval(updateRings, 1000);
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(centerX, centerY, radius, startAngle, endAngle, false);
|
||||||
|
ctx.lineWidth = 16;
|
||||||
|
ctx.strokeStyle = strokeStyle;
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
drawArc(
|
||||||
|
(seconds === 0) ? 60 : seconds,
|
||||||
|
60,
|
||||||
|
maxSize,
|
||||||
|
'black'
|
||||||
|
);
|
||||||
|
drawArc(
|
||||||
|
(minutes === 0) ? 60 : minutes,
|
||||||
|
60,
|
||||||
|
maxSize - lineWidth - lineGap,
|
||||||
|
'lightgrey'
|
||||||
|
);
|
||||||
|
drawArc(
|
||||||
|
is24HourFormat ? hours : hours % 12,
|
||||||
|
is24HourFormat ? 24 : 12,
|
||||||
|
maxSize - (lineWidth + lineGap) * 2,
|
||||||
|
'white'
|
||||||
|
);
|
||||||
|
drawArc(dayOfWeek, 7, maxSize - (lineWidth + lineGap) * 3, colorDayOfWeek);
|
||||||
|
drawArc(dayOfMonth, daysInCurrentMonth, maxSize - (lineWidth + lineGap) * 4, colorDayOfMonth);
|
||||||
|
drawArc(month, 12, maxSize - (lineWidth + lineGap) * 5, colorMonth);
|
||||||
|
}
|
||||||
|
|
||||||
function updateRings() {
|
function updateRings() {
|
||||||
currentDate = new Date();
|
const currentDate = new Date();
|
||||||
const currentSeconds = currentDate.getSeconds();
|
const currentSeconds = currentDate.getSeconds();
|
||||||
const currentMinutes = currentDate.getMinutes();
|
const currentMinutes = currentDate.getMinutes();
|
||||||
const currentHours = currentDate.getHours();
|
const currentHours = currentDate.getHours();
|
||||||
const currentDayOfWeek = getNumericWeekday(currentDate);
|
const currentDayOfWeek = getNumericWeekday(currentDate);
|
||||||
const currentDayOfMonth = currentDate.getDate();
|
const currentDayOfMonth = currentDate.getDate();
|
||||||
const currentDayOfYear = getNumericYearDay(currentDate);
|
const currentMonth = currentDate.getMonth() + 1; // Get current month (0-11)
|
||||||
currentMonth = currentDate.getMonth() + 1; // Get current month (0-11)
|
const daysInCurrentMonth = daysInMonth(currentMonth, currentDate.getFullYear());
|
||||||
daysInCurrentMonth = daysInMonth(currentMonth, currentDate.getFullYear());
|
|
||||||
|
|
||||||
drawRings(
|
drawRings(
|
||||||
currentSeconds,
|
currentSeconds,
|
||||||
|
|
@ -171,7 +90,6 @@ tags:
|
||||||
currentDayOfWeek,
|
currentDayOfWeek,
|
||||||
currentDayOfMonth,
|
currentDayOfMonth,
|
||||||
currentMonth,
|
currentMonth,
|
||||||
currentDayOfYear,
|
|
||||||
daysInCurrentMonth
|
daysInCurrentMonth
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -182,116 +100,11 @@ tags:
|
||||||
return (weekday === 0) ? 7 : weekday;
|
return (weekday === 0) ? 7 : weekday;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNumericYearDay(date) {
|
|
||||||
const start = new Date(date.getFullYear(), 0, 0);
|
|
||||||
return Math.floor((date - start) / 86400000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function daysInMonth(month, year) {
|
function daysInMonth(month, year) {
|
||||||
return new Date(year, month, 0).getDate();
|
return new Date(year, month, 0).getDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawArc(value, maxValue, radius, strokeStyle) {
|
updateRings();
|
||||||
const startAngle = -0.5 * Math.PI; // Start at the top
|
setInterval(updateRings, 1000);
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Array rings nutzen
|
|
||||||
function drawRings(seconds, minutes, hours, dayOfWeek, dayOfMonth, month, dayOfYear, daysInCurrentMonth) {
|
|
||||||
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(
|
|
||||||
// is24HourFormat ? ((hours === 0) ? 24 : hours) : hours % 12,
|
|
||||||
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);
|
|
||||||
drawArc(dayOfYear, 365, rings[5].radius, rings[5].color);
|
|
||||||
drawArc(month, 12, rings[6].radius, rings[6].color);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
@ -14,23 +14,10 @@
|
||||||
|
|
||||||
.body_clock {
|
.body_clock {
|
||||||
main {
|
main {
|
||||||
|
@extend .sec_main_center;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column nowrap;
|
flex-flow: column nowrap;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
|
||||||
height: 100vh;
|
|
||||||
width: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wrap {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
|
|
|
||||||
|
|
@ -270,7 +270,8 @@
|
||||||
padding-left: hippie.$space_double;
|
padding-left: hippie.$space_double;
|
||||||
}
|
}
|
||||||
|
|
||||||
#demo {
|
// Index
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
.wrap {
|
.wrap {
|
||||||
display: flex;
|
display: flex;
|
||||||
// height: 100%;
|
// height: 100%;
|
||||||
|
|
@ -287,4 +288,3 @@
|
||||||
background-color: hippie.$color_darker;
|
background-color: hippie.$color_darker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue