html5 canvas 钟表
2015-02-11 15:26
176 查看
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <style> body{ background:pink; } #c1{ background:white; } </style> <script> window.onload = function () { var oc = document.getElementById('c1'); 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 aDate = new Date(); var oHouse = aDate.getHours(); var oMin = aDate.getMinutes(); var oSen = aDate.getSeconds(); var oHoursevalue = ( -90 + oHouse*30 + oMin/2)*Math.PI/180; var oMinvalue = ( -90 + oMin*6 )*Math.PI/180; var oSenvalue = ( -90 + oSen*6)*Math.PI/180; ogc.beginPath(); for(var 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.stroke(); } ogc.closePath(); ogc.beginPath(); ogc.fillStyle = 'white'; ogc.moveTo(x,y); ogc.arc(x,y,r*19/20,0,360,false); ogc.fill(); ogc.closePath(); ogc.beginPath(); ogc.lineWidth = 3 for(var 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.stroke(); } ogc.closePath(); ogc.beginPath(); ogc.fillStyle = 'white'; ogc.moveTo(x,y); ogc.arc(x,y,r*18/20,0,360,false); ogc.fill(); ogc.closePath(); ogc.beginPath(); ogc.lineWidth = 5 ogc.moveTo(x,y); ogc.arc(x,y,r*5/20,oHoursevalue,oHoursevalue,false); ogc.stroke(); ogc.closePath(); ogc.beginPath(); ogc.lineWidth = 3 ogc.moveTo(x,y); ogc.arc(x,y,r*8/20,oMinvalue,oMinvalue,false); ogc.stroke(); ogc.closePath(); ogc.beginPath(); ogc.lineWidth = 1 ogc.moveTo(x,y); ogc.arc(x,y,r*18/20,oSenvalue,oSenvalue,false); ogc.stroke(); ogc.closePath(); } toDraw(); setInterval(toDraw,1000); } </script> </head> <body> <canvas id="c1" width="400" height="400"></canvas> </body> </html>
相关文章推荐
- 【飞秋】基于Html5的Canvas实现的Clocks (钟表)
- 【飞秋】基于Html5的Canvas实现的Clocks (钟表)
- HTML5 canvas时钟钟表!
- Html5学习--------canvas编写简单钟表
- 基于Html5的Canvas实现的Clocks (钟表)
- HTML5 Canvas 绘制二十四字真言钟表
- html5 canvas 绘制钟表
- HTML5元素Canvas实例之钟表
- Html5 canvas 钟表
- HTML5元素Canvas实例之钟表
- HTML5 Canvas 画钟表
- 基于Html5的Canvas实现的Clocks (钟表)
- 基于Html5的Canvas实现的Clocks (钟表)
- HTML5 canvas
- Html5 canvas学习1-描边 渐变 直线 矩形
- 基于HTML5 Canvas可撕裂布料效果
- 奇妙的HTML5 Canvas动画实例
- html5——canvas画方块功能函数
- 第五讲:使用html5中的canvas动态画出物理学上平抛运动
- HTML5 Canvas-Oreilly.Canvas.Pocket.Reference (4)