canvas动画圆形扩散
来源:互联网 发布:流量软件哪个好 编辑:程序博客网 时间:2024/05/05 03:41
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="box" style="width:600px;height:600px;margin:0 auto;border:2px solid #000;background:#000;"></div>
<script type="text/javascript">
var canvasList = document.getElementById('box');
var canvas = document.createElement('canvas');
canvasList.appendChild(canvas);
canvas.width = 600; //
canvas.height = 600;
var context=canvas.getContext("2d");
var width=600,height=600;
var arr = [];
for(var i=0;i<10;i++){
arr.push({x:parseInt(Math.random()*canvas.width),y:parseInt(Math.random()*canvas.height)});
};
var radius=10;
//创建构造函数Circle
function Circle(x,y,radius){
this.xx=x;//在画布内随机生成x值
this.yy=y;
this.radius=radius;
};
Circle.prototype.radiu=function(){
radius += 0.5; //每一帧半径增加0.5
if (this.radius >= 20) {
radius = 10;
};
};
// 绘制圆形的方法
Circle.prototype.paint=function(){
context.beginPath();
context.arc(this.xx,this.yy,10,0,Math.PI*2);
context.fillStyle="rgba(250,250,50,1)";//填充颜色,默认是黑色
context.fill();//画实心圆
context.closePath();
context.lineWidth = 2; //线条宽度
context.strokeStyle = 'rgba(250,250,50,1)'; //颜色
context.stroke();
this.paintkong();
this.paintkong(0);
this.paintkong(10);
this.paintkong(20);
};
Circle.prototype.paintkong=function(num){
context.beginPath();
context.arc(this.xx,this.yy,this.radius+num,0,Math.PI*2);
context.closePath();
context.lineWidth = 1; //线条宽度
context.strokeStyle = 'rgba(250,250,50,1)'; //颜色
context.stroke();
};
// 创建
var newfun = null;
function createCircles(){
for(var j=0;j<arr.length;j++){
newfun = new Circle(arr[j].x,arr[j].y,radius);//调用构造函数
newfun.paint();
};
newfun.radiu();
};
createCircles()
// 创建临时canvas
var backCanvas = document.createElement('canvas'),
backCtx = backCanvas.getContext('2d');
backCanvas.width = width;
backCanvas.height = height;
//设置主canvas的绘制透明度
context.globalAlpha = 0.7;
//显示即将绘制的图像,忽略临时canvas中已存在的图像
backCtx.globalCompositeOperation = 'copy';
var render = function() {
//先将主canvas的图像缓存到临时canvas中
backCtx.drawImage(canvas, 0, 0, width, height);
//清除主canvas上的图像
context.clearRect(0, 0, width, height);
//在主canvas上画新圆
createCircles();
//新圆画完后,再把临时canvas的图像绘制回主canvas中
context.drawImage(backCanvas, 0, 0, width, height);
};
setInterval("render()", 100);
</script>
</body>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="box" style="width:600px;height:600px;margin:0 auto;border:2px solid #000;background:#000;"></div>
<script type="text/javascript">
var canvasList = document.getElementById('box');
var canvas = document.createElement('canvas');
canvasList.appendChild(canvas);
canvas.width = 600; //
canvas.height = 600;
var context=canvas.getContext("2d");
var width=600,height=600;
var arr = [];
for(var i=0;i<10;i++){
arr.push({x:parseInt(Math.random()*canvas.width),y:parseInt(Math.random()*canvas.height)});
};
var radius=10;
//创建构造函数Circle
function Circle(x,y,radius){
this.xx=x;//在画布内随机生成x值
this.yy=y;
this.radius=radius;
};
Circle.prototype.radiu=function(){
radius += 0.5; //每一帧半径增加0.5
if (this.radius >= 20) {
radius = 10;
};
};
// 绘制圆形的方法
Circle.prototype.paint=function(){
context.beginPath();
context.arc(this.xx,this.yy,10,0,Math.PI*2);
context.fillStyle="rgba(250,250,50,1)";//填充颜色,默认是黑色
context.fill();//画实心圆
context.closePath();
context.lineWidth = 2; //线条宽度
context.strokeStyle = 'rgba(250,250,50,1)'; //颜色
context.stroke();
this.paintkong();
this.paintkong(0);
this.paintkong(10);
this.paintkong(20);
};
Circle.prototype.paintkong=function(num){
context.beginPath();
context.arc(this.xx,this.yy,this.radius+num,0,Math.PI*2);
context.closePath();
context.lineWidth = 1; //线条宽度
context.strokeStyle = 'rgba(250,250,50,1)'; //颜色
context.stroke();
};
// 创建
var newfun = null;
function createCircles(){
for(var j=0;j<arr.length;j++){
newfun = new Circle(arr[j].x,arr[j].y,radius);//调用构造函数
newfun.paint();
};
newfun.radiu();
};
createCircles()
// 创建临时canvas
var backCanvas = document.createElement('canvas'),
backCtx = backCanvas.getContext('2d');
backCanvas.width = width;
backCanvas.height = height;
//设置主canvas的绘制透明度
context.globalAlpha = 0.7;
//显示即将绘制的图像,忽略临时canvas中已存在的图像
backCtx.globalCompositeOperation = 'copy';
var render = function() {
//先将主canvas的图像缓存到临时canvas中
backCtx.drawImage(canvas, 0, 0, width, height);
//清除主canvas上的图像
context.clearRect(0, 0, width, height);
//在主canvas上画新圆
createCircles();
//新圆画完后,再把临时canvas的图像绘制回主canvas中
context.drawImage(backCanvas, 0, 0, width, height);
};
setInterval("render()", 100);
</script>
</body>
</html>
阅读全文
0 0
- canvas动画圆形扩散
- canvas圆形扩散
- Android圆形向外扩散颜色渐浅动画
- Android Material Design(6) CircularReveal圆形扩散动画的使用
- iOS悬浮窗UIBezierPath圆形扩散转场动画
- 纯css3圆形从中心向四周扩散动画效果
- iOS悬浮窗UIBezierPath圆形扩散转场动画
- canvas-圆形
- HTML5 canvas带渐变色的圆形进度条动画
- html5使用canvas画布制作圆形加载动画
- 自定义view实现点击圆形扩散
- android 圆圈水波扩散动画
- canvas 实现简单的图像扩散
- 【Html5】canvas绘制圆形
- HTML5 canvas 绘制圆形
- HTML5 canvas圆形
- Canvas绘制圆形
- Canvas 圆形渐变
- opencv ROI(感兴趣区域)与掩码操作 ROI图像融合
- Java与算法(3)
- Collections.sort排序
- 多进程如何调度
- 链式栈的实现
- canvas动画圆形扩散
- Java+Selenium3基础篇5-第一个自动化测试脚本
- 关于Android中WebView的点滴
- (搬运).net起步 (MemberShip 的配置)
- Java实现-重排链表
- c#中的正则表达式的源码
- 0017_Letter Combinations of a Phone Number
- Hibernate框架自学笔记
- LeetCode-62. Unique Paths