当前位置:网站首页>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>
边栏推荐
- SSM integration
- FreeRTOS内核详解(1) —— 临界段保护原理
- AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
- meime模块
- 【 application 】 life many years of operations, what turned scored 12 k + annual bonus salary?
- 广州华为面试总结
- URL模块
- 由中序遍历和后序遍历得到前序遍历(树的遍历)
- ssm各类配置模板
- 磷脂-聚乙二醇-巯基,DSPE-PEG-Thiol,DSPE-PEG-SH,MW:5000
猜你喜欢
解决glob()返回文件排序不一致问题&onnx本地按照安装方法
Knowledge Engineering Assignment 2: Introduction to Knowledge Engineering Related Fields
Debian 10 NTP 服务配置
C语言 0长度数组/柔性数组
oracle inner join and outer join
parser = argparse.ArgumentParser()解析
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified active group
Redis简单学习笔记
Cut out web icons through PS 2021
Phospholipid-Polyethylene Glycol-Aldehyde DSPE-PEG-Aldehyde DSPE-PEG-CHO MW: 5000
随机推荐
Cut out web icons through PS 2021
啃瓜记录第一天
利用 nucleo stm32 f767zi 进行USART+DMA+PWM输入模式 CUBE配置
微信小程序云开发-证件照的实现
The @autowired distinguished from @ the Resource
知识问答与知识会话的区别
AttributeError: Can't get attribute 'SPPF' on
广州华为面试总结
querystring模块
如何查看一个现有的keil工程之前由什么版本的keil IDE编译
docker 安装 sqlserver中的坑点
String comparison size in MySQL (date string comparison problem)
require modular syntax
kettle 安装与配置
DOM manipulation---magnifying glass case
Error: with open(txt_path,'r') as f: FileNotFoundError: [Errno 2] No such file or directory:
Basic usage of Monaco Editor
The difference between the knowledge question and answer session with the knowledge
canvas--pie chart
Scientific research reagent DMPE-PEG-Mal dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide