2020-02-14 06:31:24 -08:00
|
|
|
<template>
|
2020-02-14 06:55:13 -08:00
|
|
|
<svg class="mbcofsoe" viewBox="0 0 10 10" preserveAspectRatio="none">
|
|
|
|
<circle v-for="(angle, i) in graduations"
|
2021-11-19 02:36:12 -08:00
|
|
|
:key="i"
|
2020-02-14 06:31:24 -08:00
|
|
|
:cx="5 + (Math.sin(angle) * (5 - graduationsPadding))"
|
|
|
|
:cy="5 - (Math.cos(angle) * (5 - graduationsPadding))"
|
|
|
|
:r="i % 5 == 0 ? 0.125 : 0.05"
|
2020-02-14 06:55:13 -08:00
|
|
|
:fill="i % 5 == 0 ? majorGraduationColor : minorGraduationColor"
|
2021-07-19 07:31:27 -07:00
|
|
|
/>
|
2020-02-14 06:31:24 -08:00
|
|
|
|
|
|
|
<line
|
|
|
|
:x1="5 - (Math.sin(sAngle) * (sHandLengthRatio * handsTailLength))"
|
|
|
|
:y1="5 + (Math.cos(sAngle) * (sHandLengthRatio * handsTailLength))"
|
|
|
|
:x2="5 + (Math.sin(sAngle) * ((sHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:y2="5 - (Math.cos(sAngle) * ((sHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:stroke="sHandColor"
|
2021-07-19 07:31:27 -07:00
|
|
|
:stroke-width="thickness / 2"
|
2021-07-19 07:48:22 -07:00
|
|
|
stroke-linecap="round"
|
2021-07-19 07:31:27 -07:00
|
|
|
/>
|
2020-02-14 06:31:24 -08:00
|
|
|
|
|
|
|
<line
|
|
|
|
:x1="5 - (Math.sin(mAngle) * (mHandLengthRatio * handsTailLength))"
|
|
|
|
:y1="5 + (Math.cos(mAngle) * (mHandLengthRatio * handsTailLength))"
|
|
|
|
:x2="5 + (Math.sin(mAngle) * ((mHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:y2="5 - (Math.cos(mAngle) * ((mHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:stroke="mHandColor"
|
2021-07-19 07:31:27 -07:00
|
|
|
:stroke-width="thickness"
|
2021-07-19 07:48:22 -07:00
|
|
|
stroke-linecap="round"
|
2021-07-19 07:31:27 -07:00
|
|
|
/>
|
2020-02-14 06:31:24 -08:00
|
|
|
|
|
|
|
<line
|
|
|
|
:x1="5 - (Math.sin(hAngle) * (hHandLengthRatio * handsTailLength))"
|
|
|
|
:y1="5 + (Math.cos(hAngle) * (hHandLengthRatio * handsTailLength))"
|
|
|
|
:x2="5 + (Math.sin(hAngle) * ((hHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:y2="5 - (Math.cos(hAngle) * ((hHandLengthRatio * 5) - handsPadding))"
|
|
|
|
:stroke="hHandColor"
|
2021-07-19 07:31:27 -07:00
|
|
|
:stroke-width="thickness"
|
2021-07-19 07:48:22 -07:00
|
|
|
stroke-linecap="round"
|
2021-07-19 07:31:27 -07:00
|
|
|
/>
|
2020-02-14 06:31:24 -08:00
|
|
|
</svg>
|
|
|
|
</template>
|
|
|
|
|
2022-01-10 07:05:18 -08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
|
2020-02-14 06:31:24 -08:00
|
|
|
import * as tinycolor from 'tinycolor2';
|
|
|
|
|
2022-01-10 07:05:18 -08:00
|
|
|
withDefaults(defineProps<{
|
|
|
|
thickness: number;
|
|
|
|
}>(), {
|
|
|
|
thickness: 0.1,
|
|
|
|
});
|
2020-02-14 06:31:24 -08:00
|
|
|
|
2022-01-10 07:05:18 -08:00
|
|
|
const now = ref(new Date());
|
|
|
|
const enabled = ref(true);
|
|
|
|
const graduationsPadding = ref(0.5);
|
|
|
|
const handsPadding = ref(1);
|
|
|
|
const handsTailLength = ref(0.7);
|
|
|
|
const hHandLengthRatio = ref(0.75);
|
|
|
|
const mHandLengthRatio = ref(1);
|
|
|
|
const sHandLengthRatio = ref(1);
|
|
|
|
const computedStyle = getComputedStyle(document.documentElement);
|
|
|
|
|
|
|
|
const dark = computed(() => tinycolor(computedStyle.getPropertyValue('--bg')).isDark());
|
|
|
|
const majorGraduationColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.3)');
|
|
|
|
const minorGraduationColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)');
|
|
|
|
const sHandColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.3)');
|
|
|
|
const mHandColor = computed(() => tinycolor(computedStyle.getPropertyValue('--fg')).toHexString());
|
|
|
|
const hHandColor = computed(() => tinycolor(computedStyle.getPropertyValue('--accent')).toHexString());
|
|
|
|
const s = computed(() => now.value.getSeconds());
|
|
|
|
const m = computed(() => now.value.getMinutes());
|
|
|
|
const h = computed(() => now.value.getHours());
|
|
|
|
const hAngle = computed(() => Math.PI * (h.value % 12 + (m.value + s.value / 60) / 60) / 6);
|
|
|
|
const mAngle = computed(() => Math.PI * (m.value + s.value / 60) / 30);
|
|
|
|
const sAngle = computed(() => Math.PI * s.value / 30);
|
|
|
|
const graduations = computed(() => {
|
|
|
|
const angles: number[] = [];
|
|
|
|
for (let i = 0; i < 60; i++) {
|
|
|
|
const angle = Math.PI * i / 30;
|
|
|
|
angles.push(angle);
|
|
|
|
}
|
2020-02-14 06:31:24 -08:00
|
|
|
|
2022-01-10 07:05:18 -08:00
|
|
|
return angles;
|
|
|
|
});
|
2020-02-14 06:31:24 -08:00
|
|
|
|
2022-01-10 07:05:18 -08:00
|
|
|
function tick() {
|
|
|
|
now.value = new Date();
|
|
|
|
}
|
2020-02-14 06:31:24 -08:00
|
|
|
|
2022-01-10 07:05:18 -08:00
|
|
|
onMounted(() => {
|
|
|
|
const update = () => {
|
|
|
|
if (enabled.value) {
|
|
|
|
tick();
|
|
|
|
setTimeout(update, 1000);
|
2020-02-14 06:31:24 -08:00
|
|
|
}
|
2022-01-10 07:05:18 -08:00
|
|
|
};
|
|
|
|
update();
|
|
|
|
});
|
2020-02-14 06:31:24 -08:00
|
|
|
|
2022-01-10 07:05:18 -08:00
|
|
|
onBeforeUnmount(() => {
|
|
|
|
enabled.value = false;
|
2020-02-14 06:31:24 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2020-02-14 06:55:13 -08:00
|
|
|
.mbcofsoe {
|
2020-02-14 06:31:24 -08:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|