当前位置:网站首页>钟表刻度线
钟表刻度线
2022-08-02 03:22:00 【cjx177187】
钟表
思路:
- 画一个圆
- 给圆上画上刻度线
- 将圆划分为60分,每份上画出线
- 利用if判断每五个将线条延长,当作小时的刻度
- 利用计时器画出时针,分针,秒针
<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
//钟表框
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()
}
//计时器运转秒针
setInterval(function () {
canvas.width = 600
seconds()
hours()
minutes()
construction()
}, 1000)
</script>
边栏推荐
- Source Insight 使用教程(2)——常用功能
- 3分钟带你了解微信小程序开发
- subprocess.CalledProcessError: Command 'pip install 'thop'' returned non-zero exit status 1.
- ssm各类配置模板
- 小程序 van-cell 换行能左对齐问题
- DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group
- Phospholipid-polyethylene glycol-thiol, DSPE-PEG-Thiol, DSPE-PEG-SH, MW: 5000
- SSM integration
- 广州华为面试总结
- debian 10 nat 与路由转发
猜你喜欢

啃瓜记录又一天

The @autowired distinguished from @ the Resource

MySQL分组后取最大一条数据【最优解】

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

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

Chapter 10 Clustering

STM32 CAN过滤器

一个结构体 = 另一个结构体(同类型结构体之间可直接赋值操作)

Source Insight 使用教程(2)——常用功能

parser = argparse.ArgumentParser()解析
随机推荐
MySQL分页查询的5种方法
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
The usage of json type field in mysql
AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
C语言入门小游戏—三子棋
广州华为面试总结
磷脂-聚乙二醇-酰肼,DSPE-PEG-Hydrazide,DSPE-PEG-HZ,MW:5000
Phospholipid-polyethylene glycol-hydrazide, DSPE-PEG-Hydrazide, DSPE-PEG-HZ, MW: 5000
C语言 内联函数
COCO数据集训练TPH-YoloV5
mysql卸载详细教程
require模块化语法
Debian 10 NTP 服务配置
知识问答与知识会话的区别
@Autowired详解[email protected]在static属性上的使用
MySQL常见的索引
磷脂-聚乙二醇-靶向新生血管靶向肽APRPG,DSPE-PEG-APRPG
@ApiModel 和 @ApiModelProperty
[Mianjing] Mihayou data development on one side and two sides
【深度学习】从LeNet-5识别手写数字入门深度学习