HTML5 绘制时钟
来源:互联网 发布:大月薰 知乎 编辑:程序博客网 时间:2024/06/03 20:04
效果图: cxt.closePath(); cxt.fillStyle='#000000'; cxt.beginPath(); cxt.closePath(); fillColorRadial.addColorStop(0,'red'); fillColorRadial.addColorStop(0.2,'pink'); fillColorRadial.addColorStop(0.4,'cyan'); fillColorRadial.addColorStop(0.7,'lightyellow'); cxt.fillStyle = fillColorRadial; cxt.fill();
cxt.lineWidth=7; cxt.save();
cxt.lineWidth=5; cxt.save();
cxt.lineWidth=7; cxt.save(); cxt.save(); cxt.save();
测试内容
var demo=document.getElementByIdx_x_x("demo");
var cxt=demo.getContext('2d');
function drawclock(){
cxt.clearRect(0,0,500,500);
var now=new Date();
var second=now.getSeconds();
var min=now.getMinutes();
var hour=now.getHours();
hour=hour+min/60;
min=min+second/60;
hour=hour>12?hour-12:hour;
cxt.lineWidth=10;
cxt.strokeStyle='blue';
cxt.beginPath();
cxt.arc(250,250,160,0,Math.PI,false);
cxt.arc(100,175,75,95*Math.PI/180,Math.PI*14/8,false);
cxt.arc(250,250,160,235*Math.PI/180,305*Math.PI/180,false);
cxt.arc(400,175,75,225*Math.PI/180,85*Math.PI/180,false);
cxt.stroke();
cxt.fill();
cxt.arc(250,250,160,0,Math.PI*2,false);
cxt.stroke();
//径向渐变
varfillColorRadial=cxt.createRadialGradient(250,250,0,250,250,150);
for(var i=1;i<13;i++)
{
cxt.save();
cxt.translate(250,250);
var theta=(i-3)*2*Math.PI/12;
var x=150*0.75*Math.cos(theta);
var y=150*0.75*Math.sin(theta);
cxt.fillStyle="#000000";
cxt.font="bold 14px 微软雅黑";
cxt.textAlign="center";
cxt.textBaseline="middle";
cxt.fillText(i,x,y);
cxt.restore();
}
for(var i=1;i<=60;i++)
{
cxt.save();
cxt.translate(250,250);
var theta=(i-15)*2*Math.PI/60;
var x=200*0.75*Math.cos(theta);
var y=200*0.75*Math.sin(theta);
cxt.fillStyle="green";
cxt.font="bold 1px 微软雅黑";
cxt.textAlign="center";
cxt.textBaseline="middle";
cxt.fillText(i,x,y);
cxt.restore();
}
cxt.strokeStyle='#000000';
for(var i=0;i<60;i++)
{
if(i%5==0)
{
cxt.translate(250,250);
cxt.rotate(i*30*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-120);
cxt.lineTo(0,-140);
cxt.closePath();
cxt.stroke();
cxt.restore();
}
else
{
cxt.translate(250,250);
cxt.rotate(i*6*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-130);
cxt.lineTo(0,-140);
cxt.closePath();
cxt.stroke();
cxt.restore();
}
}
//时针
cxt.translate(250,250);
cxt.rotate(hour*30*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-90);
cxt.lineTo(0,10);
cxt.closePath();
cxt.stroke();
cxt.restore();
//分针
cxt.lineWidth=5;
cxt.translate(250,250);
cxt.rotate(min*6*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-100);
cxt.lineTo(0,10);
cxt.closePath();
cxt.stroke();
cxt.restore();
//秒针
cxt.lineWidth=5;
cxt.strokeStyle='red';
cxt.translate(250,250);
cxt.rotate(second*6*Math.PI/180);
cxt.beginPath();
cxt.moveTo(0,-100);
cxt.lineTo(0,10);
cxt.closePath();
cxt.stroke();
cxt.beginPath();
cxt.arc(0,-85,5,0,Math.PI*2,false)
cxt.closePath();
cxt.lineWidth=3;
cxt.strokeStyle='red';
cxt.stroke();
cxt.fillStyle='cyan';
cxt.fill();
cxt.restore();
//交汇点装饰
cxt.lineWidth=3;
cxt.strokeStyle='red';
cxt.beginPath();
cxt.arc(250,250,5,0,Math.PI*2,false);
cxt.closePath();
cxt.stroke();
cxt.fillStyle='red';
cxt.fill();
}
setInterval(drawclock,1000);
0 0
- HTML5 绘制时钟
- Html5 Canvas 绘制 时钟
- HTML5 Canvas绘制实时时钟
- 通过html5 canvas绘制时钟
- 纯Shading Language绘制HTML5时钟
- 使用HTML5 Canvas绘制一个时钟
- HTML5 时钟
- HTML5时钟
- HTML5时钟
- html5 时钟
- html5 时钟
- html5 canvas 如何清空之前绘制的…
- C# 绘制时钟
- 动态绘制时钟
- php绘制时钟
- Qt绘制简易时钟
- 使用canvas绘制时钟
- canvas绘制时钟
- CALayer
- 每日小记2013.3.1
- Vuejs(16)——Vue插件写、用详解(附demo)
- jquery取table中某一行td的值
- Windows窗体应用程序---添加---小…
- HTML5 绘制时钟
- 用MapReduce把hdfs数据写入HBase中
- HTML5绘制太阳系
- PowerDesigner生成SQL数据库
- .NET刷新页面的六种方法
- C#操作Word模板并且修改书签
- 数据库中联合查询和连接查询的区别…
- 运用Python/Django和Swift 3开发UberEats
- WARNING: An attempt was made to authenticate the locked user "tomcat"