当前位置:网站首页 > 编程语言 > 正文

时钟的代码(时钟代码完整版)



<!DOCTYPE html> <html> <head> <meta charset=utf-8> <title>clock</title> </head> <body style="color:green; <!--background-image:url('http://image.lxway.com/upload/b/f0/bf0d97dceee6edbc89d4963_thumb.png');--> background-size:100%; background-repeat: no-repeat; background-attachment:fixed"> <div style="width: 900px; height: 900px; margin-top: 50px; margin-left: 50px;"> <div style="position: absolute; left:119px;top: 193px; width: 900px; height: 900px; background-image:url('http://image.lxway.com/upload/b/f0/bf0d97dceee6edbc89d4963_thumb.png'); background-repeat: no-repeat; z-index: -1;"> </div> <canvas id="t" width="800" height="800"></canvas> <div style="position: absolute; left:118px;top: 464px; width: 100px; height: 200px; background-color: white; background-repeat: no-repeat; z-index: 10;"> </div> </div> <script language="javascript"> var s = setInterval(moveI, 1000); function moveI() { var c = document.getElementById("t"); var pc = c.getContext("2d"); c.height = c.height; //  pc.lineWidth = 3; pc.strokeStyle = 'rgba(255,0,0,0.8)'; var now = new Date(); var sindex = getxy(150, now.getSeconds()); pc.moveTo(400, 400); pc.lineTo(sindex.x, sindex.y); pc.stroke(); pc.beginPath(); //  pc.lineWidth = 7; pc.strokeStyle = 'rgba(50,50,50,0.8)'; var mindex = getxy(120, now.getMinutes() + (now.getSeconds() / 60)); pc.moveTo(400, 400); pc.lineTo(mindex.x, mindex.y); pc.stroke(); pc.beginPath(); //  pc.lineWidth = 10; pc.strokeStyle = 'rgba(0,0,0,0.8)'; var hindex = getxy(80, ((now.getHours() > 12 ? now.getHours() - 12 : now.getHours()) + (now.getMinutes() / 60)) * 5); pc.moveTo(400, 400); pc.lineTo(hindex.x, hindex.y); pc.stroke(); }; function getxy(r, t) { //计算分区 0,1,2,3 var a = parseInt(t / 15); //分区角度  t = t - 15 * a; var y; var x; //基于分区的坐标计算 switch (a) { case 0: y = r - (r * Math.cos(2 * Math.PI / 360 * 90 * (t / 15))); x = r + (r * Math.sin(2 * Math.PI / 360 * 90 * (t / 15))); break; case 1: y = r + (r * Math.sin(2 * Math.PI / 360 * 90 * (t / 15))); x = r + (r * Math.cos(2 * Math.PI / 360 * 90 * (t / 15))); break; case 2: y = r + (r * Math.cos(2 * Math.PI / 360 * 90 * (t / 15))); x = r - (r * Math.sin(2 * Math.PI / 360 * 90 * (t / 15))); break; case 3: y = r - (r * Math.sin(2 * Math.PI / 360 * 90 * (t / 15))); x = r - (r * Math.cos(2 * Math.PI / 360 * 90 * (t / 15))); break; default: break; } y = (400 - r) + y; x = (400 - r) + x; return { 'x': x, 'y': y }; }; </script> </body> </html>
到此这篇时钟的代码(时钟代码完整版)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 手机本机信息怎么查看(手机本机信息怎么查看内存)2024-12-11 16:00:04
  • tkdd期刊含金量(tkde期刊的影响因子)2024-12-11 16:00:04
  • 条件变量用法(条件变量的使用)2024-12-11 16:00:04
  • 跨域是什么,如何解决跨域(跨域是什么 怎么解决)2024-12-11 16:00:04
  • linux安装yum命令在线安装(linux 在线安装)2024-12-11 16:00:04
  • pem文件和key文件(pek文件是什么意思)2024-12-11 16:00:04
  • 单片机程序编写代码(单片机如何编写程序)2024-12-11 16:00:04
  • libxml2.dll(libxml2.dll,无法继续执行代码)2024-12-11 16:00:04
  • vs怎么调试(vs怎么调试代码)2024-12-11 16:00:04
  • 爱普生c7000参数(爱普生 v700)2024-12-11 16:00:04
  • 全屏图片