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的值根据一定的函数计算得到,比如正弦.余弦函数的组合等等,可以得到一个看似不错的地形或者 ...
随机推荐
- opencv python:图像直方图 histogram
直接用matplotlib画出直方图 def plot_demo(image): plt.hist(image.ravel(), 256, [0, 256]) # image.ravel()将图像展开 ...
- PTA的Python练习题(十六)
第4章-15 换硬币 挺难的,这里学到一个range的用法: 也就是说range函数能实现顺序和倒序,取决于step是正是负 count = 0 x = int(input()) a = x // 5 ...
- A Simple Problem with Integers(树状数组区间变化和区间求和)
You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...
- idea 快捷使用(一)条件断点的使用
调试的时候,在循环里增加条件判断,可以极大的提高效率,心情也能愉悦.以下介绍下IDEA使用条件[Condition]断点的方法 1.编写一段样例代码 /** * @author jiashubing ...
- 传奇衣服、翅膀、武器、怪物、NPC等外观代码计算方法与公式
详细介绍humX.wil weaponX.wil itemsX.wil dnitemsX.wil stateitemX.wil monX.wil代码计算方法 以下计算方法适用于HERO引擎和3K ...
- vscode安装过的插件
1.VSCode的Vue插件Vetur设置,alt+shift+f格式化 对应配置 今天看到的文章安装插件可以参考: https://blog.csdn.net/maixiaochai/article ...
- Shiro入门基础
Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能. Authentication:身份认证/登录,验证用户是不是拥有相应的身份: Authorization:授权,即 ...
- javascript 原型继承 与class extends 继承对比
//父类 Animal function Animal (name) { this.name = name; this.sleep = function () { console.log(this ...
- Codeforces Round #619 (Div. 2) A. Three Strings
You are given three strings aa , bb and cc of the same length nn . The strings consist of lowercase ...
- java里判断字符串是否为数字类型的方法
String type = "数字类型";if(StringUtils.isNotBlank(value)){ //区分正负数 if(value.startsWith(" ...