canvas画布,时钟
原理代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
canvas{
margin: 20px 400px ;
}
</style>
</head>
<body>
<canvas width="500px" height="500px"></canvas> <script>
var can=document.getElementsByTagName("canvas")[];
var x=can.getContext("2d"); function clock(){ //每次执行代码清楚一次画布
x.clearRect(,,,) //创建一个实心圆
x.beginPath();
x.fillStyle="blue";
x.arc(,,,Math.PI*/,Math.PI*/)
x.fill()
x.closePath(); //再来一个白色的小圆
x.beginPath();
x.fillStyle="#ffffff";
x.arc(,,,Math.PI*/,Math.PI*/)
x.fill()
x.closePath(); //分钟刻度
for(var i=;i<;i++){
x.save()
x.beginPath();
x.lineWidth=;
x.translate(,)
x.rotate(i**Math.PI/)
x.moveTo(,)
x.lineTo(,)
x.stroke()
x.closePath();
x.restore()
} //时钟刻度
for(var a=;a<;a++){
x.save();
x.beginPath()
x.lineWidth=;
x.translate(,);
x.rotate(a**Math.PI/);
x.moveTo(,)
x.lineTo(,)
x.stroke();
x.closePath();
x.restore();
} var time=new Date();
var miao=time.getSeconds();
var fen=time.getMinutes() + miao/;
var hours=time.getHours() + fen/;
if(hours>){
hours=hours-
} x.beginPath()
x.font="20px 黑体"
x.strokeText(time.toLocaleString(),,)
x.closePath(); //时
x.save()
x.translate(,)
x.lineWidth=;
x.beginPath();
x.rotate(hours**Math.PI/)
x.moveTo(,);
x.lineTo(,-)
x.stroke()
x.closePath();
x.restore() //分
x.save()
x.beginPath();
x.translate(,)
x.lineWidth=;
x.rotate(fen**Math.PI/)
x.moveTo(,);
x.lineTo(,-)
x.stroke()
x.closePath();
x.restore() //秒
x.save()
x.beginPath();
x.translate(,)
x.lineWidth=;
x.rotate(miao**Math.PI/)
x.moveTo(,);
x.lineTo(,-)
x.stroke()
x.closePath();
x.restore() //秒针上的小圆点 x.save()
x.beginPath();
x.translate(,)
x.rotate(miao**Math.PI/)
x.fillStyle="blue";
x.arc(,-,,,Math.PI*/)
x.fill()
x.closePath();
x.restore() //中心蓝色小圆点 x.beginPath();
x.fillStyle="blue"
x.arc(,,,,Math.PI*/)
x.fill()
x.closePath(); //中心红色小圆点 x.beginPath();
x.fillStyle="red"
x.arc(,,,,Math.PI*/)
x.fill()
x.closePath(); }
setTimeout(clock,)
setInterval(clock,)
</script>
</body>
</html>
效果图:

canvas画布,时钟的更多相关文章
- 使用canvas绘制时钟
使用canvas绘制时钟 什么使canvas呢?HTML5 <canvas> 元素用于图形的绘制,通过脚本 (通常是JavaScript)来完成.<canvas> 标签只是图 ...
- HTML5 之Canvas 绘制时钟 Demo
<!DOCTYPE html> <html> <head> <title>Canvas 之 时钟 Demo</title> <!--简 ...
- [ZZ+CH] Html5 canvas+js 时钟
总之新Blog入驻以后,又开始老习惯,到处折腾自定义的空间,放些东西. 想起以前大一的时候做过一个Javascript的时间显示器,现在想做一个时钟,当然现在老奸巨猾,会先去看一看有前辈写过没. 前辈 ...
- canvas粒子时钟
前面的话 本文将使用canvas实现粒子时钟效果 效果展示 点阵数字 digit.js是一个三维数组,包含的是0到9以及冒号(digit[10])的二维点阵.每个数字的点阵表示是7*10大小的二维数组 ...
- canvas画时钟,重拾乐趣!
canvas时钟--效果图 一.先来简单介绍画时钟需要的canvas知识 1.在HTML页面中添加canvas元素,必须定义canvas元素的id属性值以便接下来的调用. HTML代码: <ca ...
- Canvas:时钟
这个时钟是将钟盘的圆心点移到了 canvas 画布中心点.以方便后面的方位计算 ctx.translate(width/2,height/2); 现定义一个圆盘来显出这个时钟的基本位置 ctx.sav ...
- canvas-菜鸟版画布时钟
这是以前自己练习写的一个画布时钟 <!DOCTYPE html><html lang="en"> <head> <meta charset ...
- [JS,Canvas]日历时钟
[JS,Canvas]日历时钟 Html: <!doctype html> <html> <head> <meta charset="UTF-8&q ...
- html 5 canvas画布整理
1. 创建canvas画布<canvas id="myCanvas" width="800" height="800" >< ...
- 用html5的canvas画布绘制贝塞尔曲线
查看效果:http://keleyi.com/keleyi/phtml/html5/7.htm 完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...
随机推荐
- POJ - 1984 Navigation Nightmare 种类并查集
思路:记录每个点与其根结点的横向距离和纵向距离,当知道其父节点与根结点的关系,很容易推出当前节点与根结点的关系: 直接相加即可. int p = a[x].par; a[x].dx += a[p].d ...
- uva1025 动态规划
这道题的边界是dp(T,N)=0,状态dp(i,j)表示在时间i.第j个车站最少等待时间,有三个决策:1.等1分钟 2.如果有向左的车,向左 3.若果有向右的车,向右 转移方程就是dp(i,j)=m ...
- Web自动化之Headless Chrome开发工具库
命令行运行Headless Chrome Chrome 安装(需要带梯子) 下载地址 几个版本的比较 Chromium 不是Chrome,但Chrome的内容基本来源于Chromium,这个是开源的版 ...
- css入门二-常用样式
css入门二-常用样式总结 基本标签样式 背景色background-color 高度height; 宽度width; 边框对齐以及详细设定举例 width/*宽度*/: 80%; height/*高 ...
- 随笔︱MRO-Microsoft R Open使用心得与相应内容总结
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 往期回顾: 新工具︱微软Microsoft ...
- VxWorks各部分初始化流程
一)configAll.h中定义所有定置系统配置的宏 INCLUDED SOFTWARE FACILITIES:定义了基本组件: EXCLUDED FACILITIES:定义了扩充组件,缺省不包括: ...
- Linux以字节显示内存大小
Linux以字节显示内存大小 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ free -b total used free shared buffers ca ...
- Linux显示以时间降序显示文件
Linux显示以时间降序显示文件 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ ls -lrt 总用量 56 -rw-r--r-- 1 youhaidong ...
- web开发中对缓存的使用
很久没有发表随笔了,最近工作不是太忙,抽点时间 给大家谈谈缓存吧 ; 在我从事web开发的几年实践中 接触了缓存技术 也是比较多的,在最初的 项目当中 我们用到 hibernate 的 一二级缓存, ...
- Windows--常见端口号
windows--常见端口号 此文档仅供参考,相关端口作用以国际标准为准. 端口:0 服务:Reserved 说明:通常用于分析操作系统.这一方法能够工作是因为在一些系统中"0" ...