2020-02-14 23:31:24 +09:00
|
|
|
<template>
|
2020-02-14 23:55:13 +09:00
|
|
|
<svg class="mbcofsoe" viewBox="0 0 10 10" preserveAspectRatio="none">
|
|
|
|
<circle v-for="(angle, i) in graduations"
|
2021-11-19 19:36:12 +09:00
|
|
|
:key="i"
|
2020-02-14 23:31:24 +09: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 23:55:13 +09:00
|
|
|
:fill="i % 5 == 0 ? majorGraduationColor : minorGraduationColor"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09: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 23:31:27 +09:00
|
|
|
:stroke-width="thickness / 2"
|
2021-07-19 23:48:22 +09:00
|
|
|
stroke-linecap="round"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09: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 23:31:27 +09:00
|
|
|
:stroke-width="thickness"
|
2021-07-19 23:48:22 +09:00
|
|
|
stroke-linecap="round"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09: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 23:31:27 +09:00
|
|
|
:stroke-width="thickness"
|
2021-07-19 23:48:22 +09:00
|
|
|
stroke-linecap="round"
|
2021-07-19 23:31:27 +09:00
|
|
|
/>
|
2020-02-14 23:31:24 +09:00
|
|
|
</svg>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2020-02-14 23:31:24 +09:00
|
|
|
import * as tinycolor from 'tinycolor2';
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2021-07-19 23:31:27 +09:00
|
|
|
props: {
|
|
|
|
thickness: {
|
|
|
|
type: Number,
|
|
|
|
default: 0.1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-14 23:31:24 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
now: new Date(),
|
|
|
|
enabled: true,
|
|
|
|
|
|
|
|
graduationsPadding: 0.5,
|
|
|
|
handsPadding: 1,
|
|
|
|
handsTailLength: 0.7,
|
|
|
|
hHandLengthRatio: 0.75,
|
|
|
|
mHandLengthRatio: 1,
|
2020-02-16 20:20:02 +09:00
|
|
|
sHandLengthRatio: 1,
|
|
|
|
|
|
|
|
computedStyle: getComputedStyle(document.documentElement)
|
2020-02-14 23:31:24 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-02-14 23:55:13 +09:00
|
|
|
dark(): boolean {
|
2020-02-16 20:20:02 +09:00
|
|
|
return tinycolor(this.computedStyle.getPropertyValue('--bg')).isDark();
|
2020-02-14 23:55:13 +09:00
|
|
|
},
|
2020-02-16 20:20:02 +09:00
|
|
|
|
2020-02-14 23:31:24 +09:00
|
|
|
majorGraduationColor(): string {
|
|
|
|
return this.dark ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.3)';
|
|
|
|
},
|
|
|
|
minorGraduationColor(): string {
|
|
|
|
return this.dark ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)';
|
|
|
|
},
|
|
|
|
|
|
|
|
sHandColor(): string {
|
|
|
|
return this.dark ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.3)';
|
|
|
|
},
|
|
|
|
mHandColor(): string {
|
2020-02-16 20:20:02 +09:00
|
|
|
return tinycolor(this.computedStyle.getPropertyValue('--fg')).toHexString();
|
2020-02-14 23:31:24 +09:00
|
|
|
},
|
|
|
|
hHandColor(): string {
|
2020-02-16 20:20:02 +09:00
|
|
|
return tinycolor(this.computedStyle.getPropertyValue('--accent')).toHexString();
|
2020-02-14 23:31:24 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
s(): number {
|
|
|
|
return this.now.getSeconds();
|
|
|
|
},
|
|
|
|
m(): number {
|
|
|
|
return this.now.getMinutes();
|
|
|
|
},
|
|
|
|
h(): number {
|
|
|
|
return this.now.getHours();
|
|
|
|
},
|
|
|
|
|
|
|
|
hAngle(): number {
|
2020-03-22 18:18:34 +09:00
|
|
|
return Math.PI * (this.h % 12 + (this.m + this.s / 60) / 60) / 6;
|
2020-02-14 23:31:24 +09:00
|
|
|
},
|
|
|
|
mAngle(): number {
|
2020-03-22 18:18:34 +09:00
|
|
|
return Math.PI * (this.m + this.s / 60) / 30;
|
2020-02-14 23:31:24 +09:00
|
|
|
},
|
|
|
|
sAngle(): number {
|
2020-03-22 18:18:34 +09:00
|
|
|
return Math.PI * this.s / 30;
|
2020-02-14 23:31:24 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
graduations(): any {
|
|
|
|
const angles = [];
|
|
|
|
for (let i = 0; i < 60; i++) {
|
|
|
|
const angle = Math.PI * i / 30;
|
|
|
|
angles.push(angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return angles;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
const update = () => {
|
|
|
|
if (this.enabled) {
|
|
|
|
this.tick();
|
2020-03-22 18:18:34 +09:00
|
|
|
setTimeout(update, 1000);
|
2020-02-14 23:31:24 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
update();
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
beforeUnmount() {
|
2020-02-14 23:31:24 +09:00
|
|
|
this.enabled = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
tick() {
|
|
|
|
this.now = new Date();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2020-02-14 23:55:13 +09:00
|
|
|
.mbcofsoe {
|
2020-02-14 23:31:24 +09:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
</style>
|