HTML5 Canvas 小例子 旋转的时钟
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Canvas</title>
<script type="text/javascript" src="jQuery.js"></script>
</head>
<style type="text/css">
body {
padding: 0;
margin: 0;
background: black;
}
#canvas {
background: white;
margin: 100px 0 0 300px;
}
#canvas>span {
color: white;
font-size: 14px;
}
</style>
<body>
<canvas id="canvas" width="600" height="500">
<span>您的浏览器不支持</span>
</canvas>
</body>
</html>
<script type="text/javascript">
/*获取绘制环境*/
var oc = $('#canvas')[0];
canvas = oc.getContext('2d');
/*定义圆心和半径*/
var x = 250, y = 250, r = 150; var time = setInterval(function() {
ClocksWatche();
}, 1000); function ClocksWatche() {
/*清理画布*/
canvas.clearRect(0, 0, oc.width, oc.height);
/*开始绘制*/
canvas.beginPath();
for(var i = 0; i < 60; i++) {
/*绘制起始点移到圆心*/
canvas.moveTo(x, y);
/*根据圆心和半径每6度绘制一次(圆心横坐标,圆心纵坐标,其实弧度,结束弧度,是否逆时针)*/
canvas.arc(x, y, r, 6 * i * Math.PI / 180, 6 * (i + 1) * Math.PI / 180, false);
}
/*连接至起始点*/
canvas.closePath();
/*画线*/
canvas.stroke();
/*设置线的粗细*/
canvas.lineWidth = 3;
/*开始绘制*/
canvas.beginPath();
for(var i = 0; i < 60; i++) {
/*绘制起始点移到圆心*/
canvas.moveTo(x, y);
/*根据圆心和半径没30度绘制一次*/
canvas.arc(x, y, r, 30 * i * Math.PI / 180, 30 * (i + 1) * Math.PI / 180, false);
}
/*连接至起始点*/
canvas.closePath();
/*画线*/
canvas.stroke();
/*设置填充颜色*/
canvas.fillStyle = 'white';
canvas.beginPath();
canvas.moveTo(x, y);
canvas.arc(x, y, r * 14 / 15, 0, 360, false);
canvas.closePath();
canvas.fill(); var loacalDate = new Date();
var hours = loacalDate.getHours();
var minute = loacalDate.getMinutes();
var sencond = loacalDate.getSeconds();
hours = (hours * 30 - 90 + minute / 2) * Math.PI / 180;
minute = (minute * 6 - 90) * Math.PI / 180;
sencond = (sencond * 6 - 90) * Math.PI / 180; canvas.beginPath();
canvas.lineWidth = 5;
canvas.moveTo(x, y);
canvas.arc(x, y, r * 8 / 15, hours, hours, false);
canvas.stroke(); canvas.beginPath();
canvas.lineWidth = 3;
canvas.moveTo(x, y);
canvas.arc(x, y, r * 10 / 15, minute, minute, false);
canvas.stroke(); canvas.beginPath();
canvas.lineWidth = 1;
canvas.moveTo(x, y);
canvas.arc(x, y, r * 14 / 15, sencond, sencond, false);
canvas.stroke();
}
</script>
HTML5 Canvas 小例子 旋转的时钟的更多相关文章
- HTML5 Canvas 小例子 旋转的图片
<一>CSS部分 @charset "utf-8"; *{ padding:; margin:; outline: none; } #canvas{ position: ...
- HTML5 Canvas 小例子 伸缩旋转方块
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- HTML5 Canvas 小例子 简易画板
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 如何开发一个简单的HTML5 Canvas 小游戏
原文:How to make a simple HTML5 Canvas game 想要快速上手HTML5 Canvas小游戏开发?下面通过一个例子来进行手把手教学.(如果你怀疑我的资历, A Wiz ...
- HTML5 Canvas小游戏基础:用户交互
交互是游戏的根本.缺少了用户交互,游戏就不能称之为游戏,只能说是动画或电影.事件是浏览器响应用户交互操作的一种机制. 1.事件和事件执行 事件定义了用户与页面交互时产生的各种操作(主要通过鼠标或热键的 ...
- html5 canvas围绕中心点旋转
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- html5 canvas防微博旋转
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- WPF Canvas小例子
源码下载:DraggingElementsInCanvas_demo.rar
- html5 canvas绘画时钟
本示例使用HTML5 canvas,模拟显示了一个时钟, 请使用支持HTML5的浏览器预览效果: HTML部分: <!DOCTYPE html> <html lang="e ...
随机推荐
- Linux From Scratch [3]
1. 为了编译glibc,我们需要kernel header. make mrproper # clean kernel tree make INSTALL_HDR_PATH=dest headers ...
- 接口文档管理系统mindoc安装手册
硬件: centos6.9-64 mysql5.6 首先确保系统安装gcc套件 yum -y gcc 第一步,安装mysql(如果不会在Linux安装mysql,请看下面文章) http://www. ...
- 《剑指offer(第二版)》——面试题36:二叉搜索树与双向链表
具体的题目大意和参考思路在此处不详述(见<剑指offer>),实质就是在中序遍历的过程中调整指针的指向,关于中序遍历有递归和非递归两种操作,所以此处也用了两种方法. 方法1(递归法): 代 ...
- kafka服务自动关闭
解决方法: kafka启动的时候添加守护进程 bin/kafka-server-start.sh -daemon ./config/server.properties & 问题原因: 待补充. ...
- redis集群服务启动
1 启动redis服务器 redis-server.exe redis.windows.conf 需要配置config节点的bind ip 2 启动redis集群 开启redis.xx.conf 服务 ...
- hierarchical_mutex函数问题(C++ Concurrent in Action)
C++ Concurrent in Action(英文版)书上(No.52-No.53)写的hierarchical_mutex函数,只适合结合std::lock_guard使用,直接使用如果不考虑顺 ...
- laravel文件上传报错 stream_socket_sendto():
原因:文件超过限定大小或没指定临时目录 修改php.ini配置 file_uploads = On ; Temporary directory for HTTP uploaded files (wil ...
- 第16课 右值引用(3)_std::forward与完美转发
1. std::forward原型 template <typename T> T&& forward(typename std::remove_reference< ...
- GIT命令行笔记
一次常规的初始化+推送: git initgit config user.email "you@example.com"git config user.name "asm ...
- 学习js第三天小结
1.冒泡排序分析: 例:将数组[9,8,7,6,5,4,3,2,1,0]按照从小打大的顺序进行冒泡排序. 演变过程: 第一趟: 8,7,6,5,4,3,2,1,0,9 比较了9次: 第二趟: 7 ...