当前位置:网站首页>JS implementation clock
JS implementation clock
2022-06-28 02:30:00 【Minsk open source】
// console.log(“number=” + number, “index=” + index);
var rad = 2 * pi / 12 * index;
var x = Math.cos(rad) * (r - 30);
var y = Math.sin(rad) * (r - 30);
ctx.textAlign = ‘center’;
// Let the number fall at the center of the coordinate
ctx.textBaseline = ‘middle’;
ctx.fillStyle = “black”;
// The coordinates are (x,y) Where you can draw number
ctx.fillText(number, x, y);
});
// Draw scales
var i;
for (i = 0; i < 60; i++) {
var rad = (2 * pi / 60) * i;
var x = Math.cos(rad) * (r - 20) ;
// console.log(“x=” + x);
var y = Math.sin(rad) * (r - 20);
// console.log(“y=” + y);
ctx.beginPath();
// Start drawing circle
ctx.arc(x, y, 2, 0, 2 * pi);
if (i % 5 == 0) {
ctx.fillStyle = “black”;
}
else {
ctx.fillStyle = “gray”;
}
ctx.fill();
}
}
// Draw a second hand
function drawsecond(ms) {
ctx.save();
// Clear the sub path list to start a new path .
ctx.beginPath();
var rad = (2 * pi / 60)*(ms-15);
// Rotate the canvas
ctx.rotate(rad);
ctx.moveTo(-5,0);
ctx.lineTo(90,0);
ctx.lineWidth = 1;
ctx.strokeStyle = “red”;
ctx.lineCap = “round”;
ctx.stroke();
ctx.restore();
}
// Draw minute hand
function drawminute(minute) {
ctx.save();
// Clear the sub path list to start a new path .
ctx.beginPath();
var rate=(2pi/60)(minute-15);
ctx.rotate(rate);
ctx.moveTo(0,0);
ctx.lineTo(70,0);
ctx.lineWidth = 2;
ctx.lineCap=“round”;
ctx.strokeStyle = “blue”;
ctx.stroke();
ctx.restore();
}
// Draw the clock
function drawhour(hour, minute) {
// Clear the sub path list to start a new path .
ctx.save();
ctx.beginPath();
// Radians per hour
var rad = (2 * pi/12)*(hour-3) ;
// Radians per minute
var mrad = (2 * pi/12 / 60)*(minute-15);
// Rotate the canvas
ctx.rotate(rad + mrad);
// Set canvas style
ctx.lineWidth = 3;
ctx.lineCap = “round”;
ctx.strokeStyle = “black”;
ctx.moveTo(0,0);
ctx.lineTo(45,0);
ctx.stroke();
ctx.restore();
}
function start() {
ctx.clearRect(-250,-200, 500,400);
var time = new Date();
var hour = time.getHours();
console.log(hour);
var minute = time.getMinutes();
var second = time.getSeconds 《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》 Free open source Prestige search official account 【 Advanced programming 】 ();
console.log(second);
console.log(“second=”+second);
drawBackground();
drawTime();
drawhour(hour,minute);
drawminute(minute);
drawsecond(second);
}
start();
// Every time 1 Refresh every second
setInterval(start, 1000);
边栏推荐
- Take n multiple table names of a database as the values of a column in another table (the range can be a table in another database)
- Jenkins - email notification plug-in
- SQL 注入绕过(四)
- Cesium 多边形增加文字标签(polygon 加 label)多边形中心点偏移问题解决
- Prometeus 2.35.0 new features
- Anonymous Mount & named mount
- Low code solution - a low code solution for digital after-sales service covering the whole process of work order, maintenance and Finance
- [sylixos] I2C device driver creation and use
- MySQL interview question set
- Where can I open an account for foreign exchange futures? Which platform is safer for cash in and out?
猜你喜欢

How to use data-driven "customer lifecycle management" to improve lead conversion rate and customer satisfaction?

frp实现内网穿透

王心凌、谭维维 - 山海(副歌加长版) 在线试听无损FLAC下载

Jenkins - data sharing and transfer between copy artifact plug-in builds

架构高可靠性应用知识图谱 ----- 架构演进之路

766. toplitz matrix

File transfer protocol --ftp

将某数据库N多表名作为另外一张表中某一列得值(范围可以是别的数据库中得某张表)

树莓派实现温控风扇智能降温

数据治理与数据标准
随机推荐
Cesium 抗锯齿(线,边框等)
js实现时钟
Dynamic Host Configuration Protocol
Protocole de transfert de fichiers - - FTP
SQL 注入绕过(二)
利用redis bitmap实现人员在线情况监控
Solve the problem that the page cannot scroll when ionic4 uses the hammerjs gesture press event
Locust performance test - parameterization, no repetition of concurrent cyclic data sampling
Numpy----np.tile()函数解析
SQL 注入绕过(五)
Complex and inefficient logistics? Three steps to solve problems in enterprise administration
Introduction to hybrid apps
Jenkins - built in variable access
投资同业存单基金是靠谱吗,同业存单基金安全吗
Where can I open an account for foreign exchange futures? Which platform is safer for cash in and out?
【永艺XY椅】试用体验
图灵机启动顺序
STM32的通用定时器与中断
There appears to be a failure with your network connection Retrying.
stm32f1中断介绍