1、绘制时钟

<!-- js代码 -->
<script type="text/javascript">
window.onload=function(){
var oC1=document.getElementById('c1')
var oGC=oC1.getContext('2d'); function toDraw(){
var x=200;
var y=200;
var r=150; oGC.clearRect(0,0,oC1.width,oC1.height); var iDate=new Date();
var iHou=iDate.getHours();
var iMin=iDate.getMinutes();
var iSce=iDate.getSeconds(); var oHoursValue = (-90 + iHou*30 + iMin/2) * Math.PI/180;
var oMinValue = (-90 + iMin*6) * Math.PI/180;
var oSenValue = (-90 + iSce*6) * Math.PI/180; 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='#fff'; 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 = '#fff'; 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*9/20,oHoursValue,oHoursValue,false); oGC.closePath();
oGC.stroke(); oGC.lineWidth = 3;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*13/20,oMinValue,oMinValue,false); oGC.closePath();
oGC.stroke(); oGC.lineWidth = 1;
oGC.beginPath();
oGC.moveTo(x,y);
oGC.arc(x,y,r*18/20,oSenValue,oSenValue,false); oGC.closePath();
oGC.stroke();
}
setInterval(toDraw,1000);
toDraw();
}
</script>
<canvas id="c1" width="400" height="400"></canvas>

2、绘制运动的圆

 <!-- js代码 -->
<script>
window.onload=function(){
var oC=document.getElementById('c1');
var oGC=oC.getContext('2d');
var setArr=[]; setInterval(function(){//进行运动操作 oGC.clearRect(0,0,oC.width,oC.height); for(var i=0;i<setArr.length;i++){
setArr[i].r+=1;//半径每次增大1
setArr[i].c4-=0.01; if(setArr[i].c4<=0){//删除背景为透明的,避免元素过大
setArr.splice(i,1);
}
}
for(var i=0;i<setArr.length;i++){
oGC.beginPath();
oGC.fillStyle='rgba('+setArr[i].c1+','+setArr[i].c2+','+setArr[i].c3+','+setArr[i].c4+')';
oGC.moveTo(setArr[i].x,setArr[i].y);
oGC.arc(setArr[i].x,setArr[i].y,setArr[i].r,0,360*Math.PI/180,false);
oGC.closePath();
oGC.fill();
} },1000/60); setInterval(function(){//添加数据 var x=Math.floor(Math.random()*oC.width);//随机产生圆的x值
var y=Math.floor(Math.random()*oC.height);//随机产生圆的y值
var r=4;//圆的半径
//随机产生圆的颜色rgb
var c1=Math.floor(Math.random()*255);
var c2=Math.floor(Math.random()*255);
var c3=Math.floor(Math.random()*255);
var c4=1;//设置透明度 setArr.push({
x : x,
y : y,
r : r,
c1 : c1,
c2 : c2,
c3 : c3,
c4 : c4
}); },500);//往数组中放元素
}
</script>
<canvas id="c1" width="400" height="400"></canvas>

html5 Canvas绘制时钟以及绘制运动的圆的更多相关文章

  1. HTML5 Canvas(实战:绘制饼图2 Tooltip)

    继上一篇HTML5 Canvas(实战:绘制饼图)之后,笔者研究了一下如何给饼图加鼠标停留时显示的提示框. Plot对象 在开始Coding之前,笔者能够想到的最easy的方式,就是给饼图的每一个区域 ...

  2. [ZZ+CH] Html5 canvas+js 时钟

    总之新Blog入驻以后,又开始老习惯,到处折腾自定义的空间,放些东西. 想起以前大一的时候做过一个Javascript的时间显示器,现在想做一个时钟,当然现在老奸巨猾,会先去看一看有前辈写过没. 前辈 ...

  3. HTML5 Canvas爱心时钟代码

    这是一款数字时钟动画,数字又多个小爱心组成,又何问起整理,随着时间推进,每一秒钟新数字替换旧数字,旧数字离去使用天女散花动画,花是五颜六色的. 查看效果:http://hovertree.com/te ...

  4. [js高手之路] html5 canvas系列教程 - arc绘制曲线图形(曲线,弧线,圆形)

    绘制曲线,经常会用到路径的知识,如果你对路径有疑问,可以参考我的这篇文章[js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解. arc:画 ...

  5. html5 canvas绘画时钟

    本示例使用HTML5 canvas,模拟显示了一个时钟, 请使用支持HTML5的浏览器预览效果: HTML部分: <!DOCTYPE html> <html lang="e ...

  6. html5 canvas 笔记三(绘制文本和图片)

    绘制文本 fillText(text, x, y [, maxWidth])   在指定的(x,y)位置填充指定的文本,绘制的最大宽度是可选的. strokeText(text, x, y [, ma ...

  7. HTML5 Canvas ( 填充图形的绘制 ) closePath, fillStyle, fill

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. HTML5 canvas 指针时钟

    <!doctype html> <html> <head></head> <body> <canvas id="> 您 ...

  9. html5 canvas js(时钟)

    <!doctype html> <html> <head> <title>canvas</title> </head> < ...

随机推荐

  1. CMS收集器和G1收集器优缺点

    首先要知道 Stop the world的含义(网易面试):不管选择哪种GC算法,stop-the-world都是不可避免的.Stop-the-world意味着从应用中停下来并进入到GC执行过程中去. ...

  2. postgreSql 常用操作总结

    0. 启动pgsl数据库 pg_ctl -D /xx/pgdata start 1. 查看pgsl版本 pg_ctl --version 1. 命令行登录数据库 psql -U username -d ...

  3. httpClient4.5 closeableHttpClient用法

    HttpClient一 简介1.尽管java.net包提供了基本通过HTTP访问资源的功能,但它没有提供全面的灵活性和其它很多应用程序需要的功能.HttpClient就是寻求弥补这项空白的组件,通过提 ...

  4. Ubuntu操作用户账户

    Git Gerrit $是普通管员,#是系统管理员,在Ubuntu下,root用户默认是没有密码的,因此也就无法使用(据说是为了安全).想用root的话,得给root用户设置一个密码: sudo pa ...

  5. [物理学与PDEs]第5章习题4 广义 Hookean 定律的张量的对称性

    设材料是超弹性的, 并设参考构形为自然状态, 证明由线性化得到的张量 ${\bf A}=(a_{ijkl})=\sex{2\cfrac{\p \bar p_{ij}}{c_{kl}}}$ 具有以下的对 ...

  6. split host

    # encoding:utf-8 _portprog = None def split_host_port(host): """ split the host :para ...

  7. Python学习笔记-EXCEL操作

    环境Python3 创建EXCEL,覆盖性创建 #conding=utf-8 import xlwt def BuildExcel(ExcelName,SheetName,TitleList,Data ...

  8. RequireJS - 个人小入门

    quirejs : http://www.requirejs.cn/ 叶小钗  : http://www.cnblogs.com/yexiaochai/p/3214926.html app.js 展示 ...

  9. .\OBJ\test1.axf: Error: L6230W: Ignoring --entry command. Cannot find argumen 'Reset_Handler'

    原因是缺少了启动文件,startup_xxx.s,只需要把该文件添加到项目下即可,该文件如果找不到则重新建立工程,每个新的工程建立后系统都会询问是否添加启动文件,选择添加启动文件即可. 注意选择对应容 ...

  10. vue-resource post请求后台接口报400(跨域问题解决方法)

    1.打开config/index.js,在proxyTable中添写如下代码 proxyTable: { '/api': { //使用"/api"来代替"http://f ...