当前位置:网站首页>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>
边栏推荐
- IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boo
- Error in render: “TypeError: Cannot read properties of null (reading ‘0‘)“ 报错解决方案
- Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
- JJWT工具类
- 【装机】老毛桃的安装及使用
- 针对简历上的问题
- Chapter 10 Clustering
- __dirname
- 啃瓜记录又一天
- 磷脂-聚乙二醇-叠氮,DSPE-PEG-Azide,DSPE-PEG-N3,MW:5000
猜你喜欢
配置mmdet来训练Swin-Transformer之一配置环境
ModuleNotFoundError No module named 'xxx' possible solutions
Source Insight 使用教程(2)——常用功能
云服务器安装部署Nacos2.0.4版本
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
每天填坑,精卫填坑第二集,TX1 配置从固态启动,安装Pytorch
How to check whether a table is locked in mysql
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
querystring模块
啃瓜记录又一天
随机推荐
[Mianjing] Mihayou data development on one side and two sides
C语言入门小游戏—三子棋
String comparison size in MySQL (date string comparison problem)
A senior test engineer asked me these questions as soon as the interview came
ModuleNotFoundError No module named 'xxx' possible solutions
Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000
np.isnan()
动态代理工具类
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰活性基团
磷脂-聚乙二醇-巯基,DSPE-PEG-Thiol,DSPE-PEG-SH,MW:5000
np.unique()函数
SOCKS5
微信小程序实现文本安全监测
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶供应,MW:5000
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
微信小程序云开发-证件照的实现
js基础知识
The difference between the knowledge question and answer session with the knowledge
np.unique() function
Cloud server installation and deployment of Nacos 2.0.4 version