当前位置:网站首页>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);
边栏推荐
- Numpy----np.reshape()
- [Yocto RM] 2 - Yocto Project Terms
- Jenkins - Pipeline 语法
- Jenkins - accédez à la variable de paramètre personnalisée Jenkins, en traitant les espaces dans la valeur de la variable
- js实现时钟
- Shardingsphere-proxy-5.0.0 establish MySQL read / write separation connection (6)
- JS 随机数(随机数 小数)
- SQL 注入繞過(二)
- 图灵机启动顺序
- geojson 格式说明(格式详解)
猜你喜欢

Low code solution - a low code solution for digital after-sales service covering the whole process of work order, maintenance and Finance

Dynamic Host Configuration Protocol

Differences between cesium polygon extrudedheight and height

SQL injection bypass (2)

系统管理员设置了系统策略,禁止进行此安装。解决方案

Based on am335x development board arm cortex-a8 -- acontis EtherCAT master station development case

利用redis bitmap实现人员在线情况监控

技术人员如何成为技术领域专家

《低代码解决方案》——覆盖工单、维修和财务全流程的数字化售后服务低代码解决方案

ScheduledThreadPoolExecutor源码解读(二)
随机推荐
低代码DSL里面在数仓中的实践
[Yocto RM]1 - System Requirements
Prometeus 2.35.0 new features
Cesium 点击获取经纬度(二维坐标)
简单文件传输协议TFTP
Adding text labels to cesium polygons the problem of polygon center point offset is solved
Jenkins - accédez à la variable de paramètre personnalisée Jenkins, en traitant les espaces dans la valeur de la variable
Jenkins - groovy postbuild plug-in enriches build history information
Four classic training modes in comparative learning
架构高可靠性应用知识图谱 ----- 架构演进之路
技术人员如何成为技术领域专家
Deep parsing of kubernetes controller runtime
对比学习中的4种经典训练模式
架构高可靠性应用知识图谱 ----- 微服务架构图谱
Where can I open an account for foreign exchange futures? Which platform is safer for cash in and out?
【sylixos】i2c设备驱动创建和使用
JS 数组随机取值(随机数组取值)
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)
JS array random value (random array value)
205. isomorphic string