HTML5画的简单时钟
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title> <script type="text/javascript">
window.onload = function (){
var oC = document.getElementById("c1"); var oGC = oC.getContext("2d");
var x = 300;
var y = 300;
var r = 150; var h = 0;
var m = 0;
var s = 0; setInterval(function (){
var date = new Date();
h = date.getHours();
m = date.getMinutes();
s = date.getSeconds();
var f = m/2;
console.log(h + "-" + m + "-" + s + " , " + f);
html5Clock();
},1000); function html5Clock(){
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); }
oGC.closePath();
oGC.stroke(); oGC.beginPath();
oGC.fillStyle = "#fff";
oGC.arc(x,y,r-8,0,2*Math.PI);
oGC.closePath();
oGC.fill(); oGC.beginPath();
//oGC.fillStyle = "red";
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);
//oGC.lineWidth = "2";
}
oGC.closePath();
oGC.stroke(); oGC.beginPath();
oGC.arc(x,y,r-20,0,2*Math.PI);
oGC.closePath();
oGC.fill(); //秒钟
oGC.beginPath();
//oGC.strokeStyle = "#016a9f";
oGC.moveTo(x,y);
oGC.arc(x,y,r-9,6*(s-15)*Math.PI/180,6*(s-15)*Math.PI/180);
oGC.lineWidth = "1";
oGC.stroke(); //分钟
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r-12,6*(m-15)*Math.PI/180,6*(m-15)*Math.PI/180);
//oGC.lineWidth = 2;
oGC.stroke(); //时钟
oGC.beginPath();
//oGC.strokeStyle = "red";
oGC.moveTo(x,y);
oGC.arc(x,y,r-50,(30*(h-3)+(m/2))*Math.PI/180,(30*(h-3)+(m/2))*Math.PI/180);
oGC.stroke();
} html5Clock(); }
</script> </head> <body> <canvas id="c1" width="800" height="600" style="border:1px solid #ccc;"></canvas> </body>
</html>
- 有空再写注释
HTML5画的简单时钟的更多相关文章
- CSS3+HTML5特效9 - 简单的时钟
原文:CSS3+HTML5特效9 - 简单的时钟 效果演示(加快了100倍) 实现原理 利用CSS3的transform-origin 及 transform 完成以上效果. 代码及说 ...
- HTML5 之Canvas 绘制时钟 Demo
<!DOCTYPE html> <html> <head> <title>Canvas 之 时钟 Demo</title> <!--简 ...
- HTML5画:线、圆、矩形、渐变
示例一:矩形 <!DOCTYPE html><head> <meta charset=utf-8> <title>HTML5画线.圆.矩形</ti ...
- 学习笔记:HTML5 Canvas绘制简单图形
HTML5 Canvas绘制简单图形 1.添加Canvas标签,添加id供js操作. <canvas id="mycanvas" height="700" ...
- Directx11学习笔记【十一】 画一个简单的三角形--effect框架的使用
这里不再介绍effect框架的具体使用,有关effect框架使用可参考http://www.cnblogs.com/zhangbaochong/p/5475961.html 实现的功能依然是画一个简单 ...
- html5滚动页面简单写法
html5滚动页面简单写法纵向滚动比较简单 直接在外面加个高度 然后overflow-y: auto; 横向比较复杂了外面写两层 最外面一层写个宽度 overflow-x: auto;第二层 写wid ...
- Unity项目 - 简单时钟 Clock
项目展示 Github项目地址:简单时钟 Clock 制作流程 表盘绘制: 采用Aseprite 像素绘图软件绘制表盘及指针.本例钟表素材大小 256x256,存储格式为png,但发现导入Unity后 ...
- 如何用latex画一个简单的表格
latex毫无疑问是一个十分强大的论文写作工具,所以掌握它就显得非常有意义,讲一下如何画一个简单的表格,代码如下: \begin{table}\centering\begin{tabular}{||c ...
- Directx11教程(19) 画一个简单的地形
原文:Directx11教程(19) 画一个简单的地形 通常我们在xz平面定义一个二维的网格,然后y的值根据一定的函数计算得到,比如正弦.余弦函数的组合等等,可以得到一个看似不错的地形或者 ...
随机推荐
- ReLU 函数
线性整流函数(Rectified Linear Unit, ReLU),又称修正线性单元,是一种人工神经网络中常用的激活函数(activation function),通常指代以斜坡函数及其变种 为代 ...
- 一个Log-Tan积分
\[\Large\int_{0}^{\pi }\theta \ln\tan\frac{\theta }{2}\mathrm{d}\theta \] \(\Large\mathbf{Solution:} ...
- Library management system design requirements
1)软件需求说明书 1. 引言 1.1 编写目的:本需求的编写是为了研究图书管理系统软件的开发途径和应用方法.同时它也是进行项目策划.概要设计和详细设计的基础,是维护人员进行内部维护,信息更新,验收和 ...
- java NIO - DirectBuffer 和 HeapBuffer
问题 : DirectBuffer 属于堆外存,那应该还是属于用户内存,而不是内核内存? FileChannel 的read(ByteBuffer dst)函数,write(ByteBuffer sr ...
- touchstart和click 自动区分
var clickEvent = (function() { if ('ontouchstart' in document.documentElement === true) return 'touc ...
- rapidxml编写xml文件(er)
一.以rapidxml::node_declaration形式写xml文件第一行 int write(void) { ; rapidxml::xml_document<> doc; rap ...
- JS-原生的ajax
记录一下: //post需要设置请求头 setRequestHeader(name, value)name //头部的名称:这个参数不应该包括空白.冒号或换行 //value 头部的值:这个参数不应该 ...
- 【代码学习】PYHTON 元组
Python的元组与列表类似,不同之处在于元组的元素不能修改.也可进行分片 和 连接操作. 元组使用小括号,列表使用方括号. 一.访问元组 #coding=utf-8 Tuple = ('name', ...
- Python3中reduce和lambda的用法
reduce() 函数将一个数据集合(iterable[, initializer])可以看出是包含了初始化数据的,且初始化数据位列第1位,即集合中的第1个元素)中的所有数据进行下列操作:先对集合中的 ...
- SAM(后缀自动机)总结
“写sam是肯定会去写的,这样才学的了字符串,后缀数组又不会用 >ω<, sam套上数据结构的感觉就像回家一样! 里面又能剖分又能线段树合并,调试又好调,我爱死这种写法了 !qwq” SA ...