48 lines
No EOL
1 KiB
Text
48 lines
No EOL
1 KiB
Text
---
|
|
title: Clock
|
|
tags:
|
|
- demoExample
|
|
---
|
|
{% assign pageBase = "../../" -%}
|
|
{% assign bodyClass = "body_clock" -%}
|
|
{% layout "hippie/full.liquid" %}
|
|
|
|
{% block body %}
|
|
<main>
|
|
<canvas id="clock" width="512" height="512"></canvas>
|
|
</main>
|
|
{% endblock %}
|
|
|
|
{% block script %}
|
|
{{ block.super -}}
|
|
<script>
|
|
// Page script
|
|
const canvas = document.getElementById('clock');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
function drawRing(seconds) {
|
|
const centerX = canvas.width / 2;
|
|
const centerY = canvas.height / 2;
|
|
const radius = 128;
|
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
const startAngle = -0.5 * Math.PI; // Start at the top
|
|
const endAngle = startAngle + (2 * Math.PI * (seconds / 60));
|
|
|
|
ctx.beginPath();
|
|
ctx.arc(centerX, centerY, radius, startAngle, endAngle, false);
|
|
ctx.lineWidth = 16;
|
|
ctx.strokeStyle = 'black';
|
|
ctx.stroke();
|
|
}
|
|
|
|
function updateCircle() {
|
|
const currentSeconds = new Date().getSeconds();
|
|
drawRing(currentSeconds);
|
|
}
|
|
|
|
updateCircle();
|
|
setInterval(updateCircle, 1000);
|
|
</script>
|
|
{% endblock %} |