吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2886|回复: 23
收起左侧

[其他转载] html雨滴下落后扩散圆形

  [复制链接]
rundreamer 发表于 2022-4-21 15:42
html实现的雨滴下落后扩散圆形
[HTML] 纯文本查看 复制代码
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus&#174;">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>雨滴下降后扩散</title>
  <style>
	*{margin:0px;padding:0px;}
	body{
		overflow:hidden; 
	}
	#canvas{
		display:bloak;
		background:#000;
	}
  </style>
 </head>
 <body>
	<canvas id="canvas"></canvas>
 </body>
 <script type="text/javascript">
	 //动画
	window.requestAnimFrame=(function(){
		return window.requestAnimationFrame||
		window.webkitRequestAnimationFrame||
		window.mozRequestAnimationFrame||
		function(callback){
			window.setTimeout(callback,1000/60);
		}
	})();
 	var can=document.getElementById("canvas");
 	var cxt=can.getContext("2d");
 	var w=can.width=window.innerWidth;
 	var h=can.height=window.innerHeight;//浏览器的宽高
 	window.onresize=function(){
 		w=can.width=window.innerWidth;
 		h=can.height=window.innerHeight;
 	}
	var n=20;//生成多少个
	var drops=[];//数组存储雨滴
	//创建一个雨滴对象
	function Drop(){
		
	}
 	Drop.prototype={
		init:function(){//初始化雨滴的属性值
			this.x=random(0,w);
			this.y=0;
			this.vy=random(4,5);//下落加速度
			this.l=random(h*0.8,h*0.9);//雨滴的落点区域
			this.r=1;//初始半径
			this.vr=1;//圆形半径更新速度
			this.a=1;//圆形初始透明度
			this.va=0.96;//透明度更新系数
		},
		//绘制雨滴
		draw:function(){
			if (this.y>=this.l)//这时候开始绘制圆形
			{
				cxt.beginPath();
				cxt.arc(this.x,this.y,this.r,0,2*Math.PI,false);
				cxt.strokeStyle="rgba(0,255,255,"+this.a+")";
				cxt.stroke();
			}else{
				cxt.fillStyle=randColor(this.a);
				cxt.fillRect(this.x,this.y,2,10);
			}
			
			//更新
			this.update();
		},
		//更新雨滴位置
		update:function(){
			if (this.y<this.l)
			{
				this.y+=this.vy;//更新Y坐标
			}else{
				if (this.a>0.03)
				{
					this.r+=this.vr;//更新圆形半径
					if (this.r>50)//这时候慢慢消失,透明度
					{
						this.a*=this.va;
					}
				}else{
					this.init();
				}
			}
		}
	}
	//动画是用递归的
	function move(){
		
		cxt.fillStyle="rgba(0,0,0,0.1)";
		cxt.fillRect(0,0,w,h);//绘制一个透明层
//		cxt.clearRect(0,0,w,h);
		for (var i=0;i<drops.length ;i++ )
		{
			drops[i].draw();
		}
		requestAnimationFrame(move);
	}
	move();
	//延迟实例化每个雨滴
	function setDrop(){
		for (var i=0;i<n ;i++ )
		{
			setTimeout(function(){
				var drop= new Drop();
				drop.init();//初始化
				drops.push(drop);//添加到数组
			},i*200);
			//这是防止i=30;
			//(function(j){
			//	setTimeout(function(){
			//		var drop= new Drop();
			//		drop.init();//初始化
			//		drops.push(drop);//添加到数组
			//	},i*200);
			//})(i)
		}
	}
	setDrop();
	//随机颜色
	function randColor(a){
		var r=Math.floor(Math.random()*255);
		var g=Math.floor(Math.random()*255);
		var b=Math.floor(Math.random()*255);
		return "rgba("+r+","+g+","+b+","+a+")"
	}

	//drop.init();//添加属性值
	//drop.draw();
	//自己从新写了random函数
	function random(min,max){
		return Math.random()*(max-min)+min;
	}
 </script>
</html>
QQ录屏20220421153922_20220421154036.gif

免费评分

参与人数 11吾爱币 +16 热心值 +11 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
185 + 1 + 1 谢谢@Thanks!
左良渊上的骏马 + 1 + 1 我很赞同!
soenluzy + 1 + 1 我很赞同!
AItechnology + 1 + 1 我很赞同!
mrhs + 1 + 1 谢谢@Thanks!
rabbitwong + 1 我很赞同!
xiaosuobjsd + 1 + 1 谢谢@Thanks!
461735945 + 1 + 1 用心讨论,共获提升!
bjxiaoyao + 2 + 1 我很赞同!
HarryPotter01 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

maomaochong 发表于 2022-4-21 16:12
mokson 发表于 2022-4-21 15:47
角度不对,应该是椭圆形态的吧?
楼主能不能做一个烟花特效呢。谢谢 了。

或者把你显示器倒过来看就是烟花了!!!!
maomaochong 发表于 2022-4-21 16:11
mokson 发表于 2022-4-21 15:47
角度不对,应该是椭圆形态的吧?
楼主能不能做一个烟花特效呢。谢谢 了。

烟花特效不就是把这个gif旋转180度?????????
mokson 发表于 2022-4-21 15:47
角度不对,应该是椭圆形态的吧?
楼主能不能做一个烟花特效呢。谢谢 了。
hackerbob 发表于 2022-4-21 15:54
好美呀,但还是有些僵硬
bjxiaoyao 发表于 2022-4-21 16:19
内容精彩,感谢楼主分享。
星心的泪 发表于 2022-4-21 16:23
我想要烟花和星空和流星
mosar_zh 发表于 2022-4-21 16:47
感谢楼主分享。
小小/ng 发表于 2022-4-21 17:15
倒过来就是烟花
Xw丶小威 发表于 2022-4-21 17:39
试了一下,雨滴的影子还挺好看的。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-25 17:54

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表