Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
JavaScript
// SETUP var win = window, doc = document, body = doc.body; var ww = win.innerWidth, wh = win.innerHeight; var c = doc.createElement('canvas'), ctx = c.getContext("2d"); var cx = ww/2, cy = wh/2; c.width = ww; c.height = wh; body.appendChild(c); body.style.overflow = 'hidden'; win.addEventListener('resize', function(){ ww = win.innerWidth; wh = win.innerHeight; c.width = ww; c.height = wh; cx = ww/2; cy = wh/2; }); // ======================================= // SETTINGS var cfg = { count: 80, size: 2, bg: 'rgba(5,5,5, 0.2)', colors: { red: '#BE4657', white: '#fff', green: '#17987A' } }; // ======================================= // UTILS function rand(min, max) { return Math.floor(Math.random() * (max - min)) + min; } function isOOB(p) { if (p.x+p.size < 0 || p.x-p.size > ww || p.y+p.size < 0 || p.y-p.size > wh) { return true; } } // ======================================= // PARTICLE var particles = []; function Particle(i){ this.x = rand(0, ww); this.y = rand(0, wh); this.id = i; if (i == 0) { this.color = cfg.colors.white; this.size = cfg.size * 2; } else { this.size = cfg.size; this.color = cfg.colors.green; } this.vx = Math.random() * 5; this.vy = Math.random() * 5; this.angle = rand(3, 10); this.speed = ww / 2000; particles.push(this); this.update = function(){ this.x += this.vx; this.y += this.vy; this.vx *= 0.95; this.vy *= 0.95; this.angle += 0.02; if (isOOB(this)) { this.x = rand(0, ww); this.y = rand(0, wh); } if (this == particles[0]) { if (rand(0, 5) % 2) { this.vx += Math.sin(Math.floor(Math.random() * 10) - 5); this.vy += Math.sin(Math.floor(Math.random() * 10) - 5); } else { this.vx -= Math.sin(Math.floor(Math.random() * 10) - 5); this.vy -= Math.sin(Math.floor(Math.random() * 10) - 5); } } else { var dx = particles[0].x - this.x, dy = particles[0].y - this.y; var dist = Math.sqrt(dx*dx + dy*dy); if(dist <= 200) { this.color = cfg.colors.red; this.vx += dx/800; this.vy += dy/800; } else { this.color = cfg.colors.green; this.vx = Math.random() * 5; this.vy = Math.random() * 5; this.x += Math.sin((Math.PI * 1) + (this.angle) ) * this.vx; this.y += Math.cos((Math.PI * 1) + (this.angle) ) * this.vy; } } }; this.draw = function(){ ctx.beginPath(); ctx.fillStyle = this.color; // arc(x, y, radius, startAngle, endAngle, anticlockwise) ctx.arc(this.x, this.y, this.size, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); } } // ======================================= // INIT for (var i = 0; i <= cfg.count; i++) { new Particle(i); } function animate(){ ctx.globalCompositeOperation = 'source-over'; ctx.fillStyle = cfg.bg; ctx.fillRect(0, 0, ww, wh); for (var i = 0; i < particles.length; i++) { particles[i].update(); particles[i].draw(); } requestAnimationFrame(animate); } animate();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>粒子群-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号