当前位置:网站首页>clock tick marks
clock tick marks
2022-08-02 03:39:00 【cjx177187】
钟表
思路:
- 画一个圆
- Draw tick marks on the circle
- Divide the circle into60分,Draw lines on each
- 利用ifJudge every five to extend the line,as hour markers
- Use the timer to draw the hour hand,分针,秒针
<body>
<style>
#box {
border: 1px solid black;
}
</style>
<canvas id="box" width="600" height="600"></canvas>
<script>
var canvas = document.querySelector("#box")
var pen = canvas.getContext("2d")
var deg = Math.PI / 180
var x = 300
var y = 300
var r = 150
//clock frame
function construction() {
pen.beginPath()
pen.arc(y, x, r, 0 * deg, 360 * deg)
for (let i = 0; i < 60; i++) {
var x1 = r * Math.cos(6 * deg * i) + x
var y1 = r * Math.sin(6 * deg * i) + y
if (i % 5 == 0) {
a = 20
} else {
a = 10
}
var x2 = (r - a) * Math.cos(6 * deg * i) + x
var y2 = (r - a) * Math.sin(6 * deg * i) + y
pen.moveTo(x1, y1)
pen.lineTo(x2, y2)
}
pen.stroke()
}
//秒针
function seconds() {
pen.beginPath(300, 300)
pen.moveTo(300, 300)
var time = new Date().getSeconds()
var x3 = 130 * Math.cos(((6 * time) -90) * deg) + x
var y3 = 130 * Math.sin(((6 * time) -90) * deg) + y
pen.lineTo(x3, y3)
pen.stroke()
}
//时针
function hours() {
pen.beginPath(300, 300)
pen.moveTo(300, 300)
var time = new Date().getHours()
var x4 =60 * Math.cos(((120 * time)+90) * deg) + x
var y4 =60 * Math.sin(((120 * time)+90) * deg) + y
pen.lineTo(x4, y4)
pen.stroke()
}
//分针
function minutes() {
pen.beginPath(300, 300)
pen.moveTo(300, 300)
var time = new Date().getMinutes()
var x5 = 90 * Math.cos(((10 * time)-90) * deg) + x
var y5 = 90 * Math.sin(((10 * time)-90) * deg) + y
pen.lineTo(x5, y5)
pen.stroke()
}
//The chronograph runs the second hand
setInterval(function () {
canvas.width = 600
seconds()
hours()
minutes()
construction()
}, 1000)
</script>
边栏推荐
猜你喜欢
随机推荐
js 取字符串中某位置某特征的值,如华为(Huawei)=>华为
C语言 void和void *(无类型指针)
啃瓜记录又一天
骨架效果 之高级渐变,适用图片等待时
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
Cloud server installation and deployment of Nacos 2.0.4 version
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶供应,MW:5000
The @autowired distinguished from @ the Resource
Questions about your resume
The difference between the knowledge question and answer session with the knowledge
cross-domain problem solving
Chapter 10 Clustering
跨域问题解决
STM32 map文件解析
DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine supply, MW: 5000
Deveco studio Hongmeng app access network detailed process (js)
【 application 】 life many years of operations, what turned scored 12 k + annual bonus salary?
Dynamic proxy tool class
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置