当前位置:网站首页>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>
边栏推荐
猜你喜欢

oracle inner join and outer join

ModuleNotFoundError No module named 'xxx' possible solutions

Phospholipid-polyethylene glycol-targeted neovascularization targeting peptide APRPG, DSPE-PEG-APRPG

DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group

微信小程序云开发-证件照的实现

云服务器安装部署Nacos2.0.4版本

AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘

亚马逊卖家怎么提升转化率

nucleo stm32 h743 FREERTOS CUBE MX配置小记录

oracle内连接和外连接
随机推荐
URL模块
语义分割标签即像素值的巨坑,transforms.ToTensor()的错误使用
枚举法方法:(leetcode1300)转变数组后最接近目标值的数组和
DSPE-PEG-DBCO 磷脂-聚乙二醇-二苯并环辛炔 一种线性杂双官能聚乙二醇化试剂
COCO数据集训练TPH-YoloV5
如何查看一个现有的keil工程之前由什么版本的keil IDE编译
【手把手带你学nRF52832/nRF52840 · (1)开发环境搭建】
我的小笔记 =》原生微信小程序
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
String comparison size in MySQL (date string comparison problem)
PCL—point cloud data segmentation
npm--package.json---require
磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
np.isnan ()
Phospholipid-polyethylene glycol-hydrazide, DSPE-PEG-Hydrazide, DSPE-PEG-HZ, MW: 5000
SSM整合
猴子选大王(约瑟环问题)
js作用域与闭包
oracle内连接和外连接
由中序遍历和前序遍历得到后序遍历(树的遍历)