当前位置:网站首页>钟表刻度线
钟表刻度线
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>
边栏推荐
- Redis简单学习笔记
- 新工程加载YOLOV6的预训练权重问题
- 【手把手带你学nRF52832/nRF52840 · (1)开发环境搭建】
- Redis simple study notes
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/yolov5-5.0/models/commo
- Cut out web icons through PS 2021
- [Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
- Source Insight 使用教程(2)——常用功能
- querystring模块
- 利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
猜你喜欢
【手把手带你学nRF52832/nRF52840 · (1)开发环境搭建】
Redis简单学习笔记
知识工程作业2:知识工程相关领域介绍
Deveco studio 鸿蒙app访问网络详细过程(js)
subprocess.CalledProcessError: Command 'pip install 'thop'' returned non-zero exit status 1.
@Autowired与@Resource区别
啃瓜记录又一天
最新,每天填坑,Jeston TX1 精卫填坑,第一步:刷机
FreeRTOS内核详解(1) —— 临界段保护原理
[Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
随机推荐
Cut out web icons through PS 2021
URL模块
DOM操作---放大镜案例
一个结构体 = 另一个结构体(同类型结构体之间可直接赋值操作)
AttributeError: Can't get attribute 'SPPF' on
np.isnan ()
@Autowired详解[email protected]在static属性上的使用
yolov5调用ip摄像头时出现的问题
js 数组去重的常用方法
【博学谷学习记录】超强总结,用心分享 | 软件测试 接口测试基础
MySQL分区表详解
[Basic Tutorial of Remote Control Development 1] Crazy Shell Open Source Formation Drone-GPIO (Remote Control Indicator Light Control)
远程调试、无cuDnn、自定义模块无法导入问题记录
sh: 1: curl: not found
Phospholipid-polyethylene glycol-thiol, DSPE-PEG-Thiol, DSPE-PEG-SH, MW: 5000
MySQL删除表数据 MySQL清空表命令 3种方法
AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘
Mysql8.0安装教程
debian 10 nat 与路由转发
MySQL两阶段提交串讲