canvas实现钟表效果
网络编程 2021-07-04 19:20www.168986.cn编程入门
本文主要分享了canvas实现钟表效果的示例代码。具有很好的参考价值,狼蚁网站SEO优化跟着长沙网络推广一起来看下吧
效果如下:
代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>canvas画钟表</title> <style> body{ background: #fc0; } #canvas1{ background: #fff; } </style> </head> <body> <canvas id="canvas1" width="400" height="400"></canvas> <script> var oC=document.getElementById('canvas1'); var oGC=oC.getContext('2d'); function toDraw(){ var x=200; var y=200; var r=150; oGC.clearRect(0,0,oC.width,oC.height); var oDate=new Date(); var oHour=oDate.getHours(); var oMinu=oDate.getMinutes(); var oSec=oDate.getSeconds(); var hVal=(-90+oHour*30+oMinu/2)*Math.PI/180; var mVal=(-90+oMinu*6)*Math.PI/180; var sVal=(-90+oSec*6)*Math.PI/180; oGC.beginPath(); for(i=0;i<60;i++){ oGC.moveTo(x,y); oGC.arc(x,y,r,6*i*Math.PI/180,6*(i+1)*Math.PI/180,false); } oGC.closePath(); oGC.stroke(); oGC.fillStyle='#fff'; oGC.beginPath(); oGC.moveTo(x,y); oGC.arc(x,y,r*19/20,0,360*Math.PI/180,false); oGC.closePath(); oGC.fill(); oGC.lineWidth=3; oGC.beginPath(); for(i=0;i<12;i++){ oGC.moveTo(x,y); oGC.arc(x,y,r,30*i*Math.PI/180,30*(i+1)*Math.PI/180,false); } oGC.closePath(); oGC.stroke(); oGC.fillStyle='#fff'; oGC.beginPath(); oGC.moveTo(x,y); oGC.arc(x,y,r*18/20,0,360*Math.PI/180,false); oGC.closePath(); oGC.fill(); oGC.lineWidth=5; oGC.beginPath(); oGC.moveTo(x,y); oGC.arc(x,y,r*10/20,hVal,hVal,false); oGC.closePath(); oGC.stroke(); oGC.lineWidth=3; oGC.beginPath(); oGC.moveTo(x,y); oGC.arc(x,y,r*14/20,mVal,mVal,false); oGC.closePath(); oGC.stroke(); oGC.lineWidth=1; oGC.beginPath(); oGC.moveTo(x,y); oGC.arc(x,y,r*17/20,sVal,sVal,false); oGC.closePath(); oGC.stroke(); } setInterval(toDraw,1000); toDraw(); </script> </body> </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持狼蚁SEO!
上一篇:js实现打地鼠小游戏
下一篇:深入理解Javascript箭头函数中的this
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程