首页 技术 正文
技术 2022年11月11日
0 收藏 381 点赞 3,066 浏览 1937 个字

<!DOCTYPE html>
<html charset=”utf-8″>
<head>
<title>时钟</title>
<style>
body{background:#42426F;}
#c1{background:white;}
span{color: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 oDate = new Date();
var oHours = oDate.getHours();
var oMin = oDate.getMinutes();
var oSen = oDate.getSeconds();

var oHoursValue = (-90 + oHours*30 + oMin/2) * Math.PI/180;
var oMinValue = (-90 + oMin*6) * Math.PI/180;
var oSenValue = (-90 + oSen*6) * Math.PI/180;
var osen2Value = oSenValue+Math.PI;

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.closePath();
oGC.stroke();

oGC.fillStyle = ‘white’;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*19/20,0,360*(i+1)*Math.PI/180,false);
oGC.closePath();
oGC.fill();

oGC.lineWidth=3;
oGC.beginPath();
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.closePath();
oGC.stroke();

oGC.fillStyle = ‘white’;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*18/20,0,360*(i+1)*Math.PI/180,false);
oGC.closePath();
oGC.fill();
//时针
oGC.lineWidth = 5;

oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*10/20,oHoursValue,oHoursValue,false);
oGC.closePath();
oGC.stroke();
//分针
oGC.lineWidth = 3;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*15/20,oMinValue,oMinValue,false);
oGC.closePath();
oGC.stroke();
//秒针
oGC.lineWidth = 1;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*17/20,oSenValue,oSenValue,false);
oGC.closePath();
oGC.stroke();
oGC.lineWidth = 1;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*5/20,osen2Value,osen2Value,false);
oGC.closePath();
oGC.stroke();

oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*1/20,0,2*Math.PI,false);
oGC.fillStyle=’black’;
oGC.closePath();
oGC.fill();

}
setInterval(toDraw,1000);
toDraw();
};
</script>
</head>
<body>
<canvas id=”c1″ width=”500″ height=”500″>
<span>不支持canvas浏览器</span>
</canvas><!–默认宽300,高150–>
</body>
</html>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,488
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289