Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body, html { margin: 0px; padding: 0px; position: fixed; background: rgb(30,30,30); }
JavaScript
function genFF(cols,rows,res,scl,t,detail1,detail2){ this.data = new Array(cols); for(var i = 0; i < cols; i++){ this.data[i] = new Array(rows); for(var j = 0; j < rows; j++){ noiseDetail(detail1, detail2); this.data[i][j] = noise(scl*i/res,scl*j/res,t)*5*Math.PI; } } return this.data; } function showFF(FF,res,c,f){ for(var x = 0; x < FF.length; x++){ for(var y = 0; y < FF[x].length; y++){ c.beginPath(); c.lineTo(res*x+res/2,res*y+res/2); c.lineTo(res*x+res/2+f*Math.cos(FF[x][y]),res*y+res/2+f*Math.sin(FF[x][y])); c.strokeStyle="white"; c.lineWidth="0.5"; c.stroke(); } } } new p5(); var canvas = document.createElement("canvas"), c = canvas.getContext("2d"), canvas2 = document.createElement("canvas2"), c2 = canvas.getContext("2d"), w = (canvas.width = canvas2.width = window.innerWidth), h = (canvas.height = canvas2.height = window.innerHeight); document.body.appendChild(canvas); document.body.appendChild(canvas2); class particle { constructor(res, mx, my) { this.opacity = 1; this.area = 100; this.ang = Math.random() * 2 * Math.PI; if ( mx < w - this.area / 2 || mx < this.area / 2 || my < h - this.area / 2 || my < this.area / 2 ) { this.pos = { x: mx + Math.random() * this.area / 2 * Math.cos(this.ang), y: my + Math.random() * this.area / 2 * Math.sin(this.ang) }; } else { this.pos = { x: Math.random() * w, y: Math.random() * h }; } this.vx = 0; this.vy = 0; this.cache = []; this.i = Math.round(this.pos.x / res); this.j = Math.round(this.pos.y / res); this.l = Math.random() * 100; this.f = this.l / 10; this.os = Math.random()*0.02+0.01; } move(ff, mx, my) { this.opacity -= this.os; this.i = Math.abs(Math.round(this.pos.x / res) - 1); this.j = Math.abs(Math.round(this.pos.y / res) - 1); this.ang = ff[this.i][this.j]; this.vx = this.f * Math.cos(this.ang); this.vy = this.f * Math.sin(this.ang); this.pos.x += this.vx; this.pos.y += this.vy; if (this.cache.length > this.l) { this.cache.splice(0, 1); } if ( this.pos.x <= 0 || this.pos.x >= w || this.pos.y <= 0 || this.pos.y >= h || this.opacity <= 0 || isNaN(this.pos.x) || isNaN(this.pos.y) || this.pos.x == undefined || this.pos.y == undefined ) { this.opacity = 1; this.ang = Math.random() * 2 * Math.PI; if ( mx < w - this.area / 2 || mx < this.area / 2 || my < h - this.area / 2 || my < this.area / 2 ) { this.pos = { x: mx + Math.random() * this.area / 2 * Math.cos(this.ang), y: my + Math.random() * this.area / 2 * Math.sin(this.ang) }; } else { this.pos = { x: Math.random() * w, y: Math.random() * h }; } this.vx = 0; this.vy = 0; this.cache = []; this.i = Math.round(this.pos.x / res); this.j = Math.round(this.pos.y / res); } this.cache.push({ x: this.pos.x, y: this.pos.y }); } show() { // c.beginPath(); // for(var i = 0; i < this.cache.length; i++){ // c.lineTo(this.cache[i].x,this.cache[i].y); // } // c.strokeStyle="rgba(255,255,255," + this.opacity + ")"; // c.lineWidth="0.1"; // c.stroke(); c.fillStyle = "rgba(255,255,255," + this.opacity + ")"; c.fillRect(this.pos.x, this.pos.y, 0.5, 0.5); } } var t = 0, res = 10, p = [], FF = [], ct = 0; function draw1() { if (p.length < 6000) { for (var k = 0; k < 100; k++) { p.push(new particle(res, mouse.x, mouse.y)); } } FF = genFF(Math.floor(w / res) + 1, Math.floor(h / res) + 1, res, 0.5, ct, 0, 0); //showFF(FF,res,c2,5); t += 0.01; ct = noise(t)*5; for (var l = 0; l < p.length; l++) { p[l].move(FF, mouse.x, mouse.y); p[l].show(); } } var mouse = { x: w / 2, y: h / 2 }; var last_mouse = { x: 0, y: 0 }; canvas.addEventListener( "mousemove", function(e) { last_mouse.x = mouse.x; last_mouse.y = mouse.y; mouse.x = e.pageX - this.offsetLeft; mouse.y = e.pageY - this.offsetTop; }, false ); canvas.addEventListener("mouseleave", function(e) { mouse.x = w / 2; mouse.y = h / 2; }); window.requestAnimFrame = (function() { return ( window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60); } ); })(); function loop1() { setTimeout(function() { window.requestAnimFrame(loop1); for (var k = 0; k < 1; k++) { c.clearRect(0, 0, w, h); draw1(); } }, 1000 / 60); } window.addEventListener("resize", function() { (w = canvas.width = window.innerWidth), (h = canvas.height = window.innerHeight); c.clearRect(0, 0, w, h); draw1(); }); loop1();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas粒子烟雾-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号