Canvas snow

Developer
Size
2,572 Kb
Views
6,072

How do I make an canvas snow?

Just a test demo . What is a canvas snow? How do you make a canvas snow? This script and codes were developed by IEkiller on 17 January 2023, Tuesday.

Canvas snow Previews

Canvas snow - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>canvas snow</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="iDiv">	<input type="button" value="小雪"/>	<input type="button" value="中雪"/>	<input type="button" value="大雪"/>	</div>	<canvas id="can1" width= 1000 height=800 ></canvas> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Canvas snow - Script Codes CSS Codes

body{ background:#333;}	#iDiv{width:200px; height:30px; background: #333; position: fixed; right:50px; bottom:30px;}

Canvas snow - Script Codes JS Codes

window.onload = function(){	var oSnow = new SnowCan({num:'500'});	var iDiv = document.getElementById('iDiv');	var aInput = iDiv.getElementsByTagName('input');	aInput[0].onclick = function(){	oSnow.num = 100;	oSnow.init();	}	aInput[1].onclick = function(){	oSnow.num = 500;	oSnow.init();	}	aInput[2].onclick = function(){	oSnow.num = 1000;	oSnow.init();	}	}	function SnowCan(oJson){	var oJson = oJson || {},	oC = document.getElementById(oJson.id) || document.getElementsByTagName('canvas')[0];	this.oCG = oC.getContext('2d'); this.oCG.clipContent= false;	this.num = oJson.num || 100;	this.aColor = oJson.aColor || ['#fff','#eee'];	this.GLSpeed = oJson.GLspeed || 0;	this.aSnowW = [1,2,3];	this.docW = oJson.docW || oC.width;	this.docH = oJson.docH || oC.height;	this.timer = null;	this.jPo = {	x : [],	y : []	};	this.jSp = {	x : [1,0.5,1.2,-1,-0.5],	y : [1.5,2.5,3.8,3.5]	};	this.init();	var _this = this;	this.timer = setInterval(function(){	_this.oCG.clearRect(0,0,_this.docW, _this.docH);	_this.creatArc();	},1000/60);	}	SnowCan.prototype.init = function(){	this.jPo.x = toRandom(-this.docW, this.docW, this.num);	this.jPo.y = toRandom(-this.docH, this.docH, this.num);	this.oCG.fillStyle = this.aColor[0];	this.creatArc();	console.log(this.jPo)	}	SnowCan.prototype.creatArc = function(){	for( var i = 0; i< this.num ; i++){	this.oCG.beginPath();	this.oCG.arc(this.jPo.x[i], this.jPo.y[i], this.aSnowW[i%this.aSnowW.length], 0 ,2*Math.PI);	this.oCG.closePath();	this.oCG.fill();	this.jPo.x[i]+= this.jSp.x[i%this.jSp.x.length]/2 ;	this.jPo.y[i]+= this.jSp.y[i%this.jSp.y.length]/2;	if(this.jPo.x[i] > this.docW + 10 || this.jPo.x[i] < 0 - 10 || this.jPo.y[i] > this.docH + 10){	this.jPo.x[i] = getRandom(0, this.docW);	this.jPo.y[i] = getRandom(-100, 0);	}	}	}	function toRandom(iMin,iMax,iNum){	var json={};	var arr=[];	while(arr.length<iNum)	{	var rnum=Math.floor(Math.random()*(iMax-iMin))+iMin;	if(!json[rnum])	{	json[rnum]=rnum;	arr.push(rnum);	}	}	return arr;	}
function getRandom(iMin,iMax){	return Math.round(Math.random()*(iMax-iMin))+iMin;
}
Canvas snow - Script Codes
Canvas snow - Script Codes
Home Page Home
Developer IEkiller
Username win7killer
Uploaded January 17, 2023
Rating 3
Size 2,572 Kb
Views 6,072
Do you need developer help for Canvas snow?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

IEkiller (win7killer) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!