Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html, body{ overflow: hidden; background: #000; padding: 0px; margin: 0px; }
JavaScript
!function(t){var o=t.noise={};function r(t,o,r){this.x=t,this.y=o,this.z=r}r.prototype.dot2=function(t,o){return this.x*t+this.y*o},r.prototype.dot3=function(t,o,r){return this.x*t+this.y*o+this.z*r};var n=[new r(1,1,0),new r(-1,1,0),new r(1,-1,0),new r(-1,-1,0),new r(1,0,1),new r(-1,0,1),new r(1,0,-1),new r(-1,0,-1),new r(0,1,1),new r(0,-1,1),new r(0,1,-1),new r(0,-1,-1)],e=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180],a=new Array(512),i=new Array(512);o.seed=function(t){t>0&&t<1&&(t*=65536),(t=Math.floor(t))<256&&(t|=t<<8);for(var o=0;o<256;o++){var r;r=1&o?e[o]^255&t:e[o]^t>>8&255,a[o]=a[o+256]=r,i[o]=i[o+256]=n[r%12]}},o.seed(0);var d=.5*(Math.sqrt(3)-1),f=(3-Math.sqrt(3))/6,h=1/6;function u(t){return t*t*t*(t*(6*t-15)+10)}function s(t,o,r){return(1-r)*t+r*o}o.simplex2=function(t,o){var r,n,e=(t+o)*d,h=Math.floor(t+e),u=Math.floor(o+e),s=(h+u)*f,l=t-h+s,w=o-u+s;l>w?(r=1,n=0):(r=0,n=1);var v=l-r+f,M=w-n+f,c=l-1+2*f,p=w-1+2*f,y=i[(h&=255)+a[u&=255]],x=i[h+r+a[u+n]],m=i[h+1+a[u+1]],q=.5-l*l-w*w,z=.5-v*v-M*M,A=.5-c*c-p*p;return 70*((q<0?0:(q*=q)*q*y.dot2(l,w))+(z<0?0:(z*=z)*z*x.dot2(v,M))+(A<0?0:(A*=A)*A*m.dot2(c,p)))},o.simplex3=function(t,o,r){var n,e,d,f,u,s,l=(t+o+r)*(1/3),w=Math.floor(t+l),v=Math.floor(o+l),M=Math.floor(r+l),c=(w+v+M)*h,p=t-w+c,y=o-v+c,x=r-M+c;p>=y?y>=x?(n=1,e=0,d=0,f=1,u=1,s=0):p>=x?(n=1,e=0,d=0,f=1,u=0,s=1):(n=0,e=0,d=1,f=1,u=0,s=1):y
maxSpeed) { this.vel.setLength(maxSpeed); } this.acc.setLength(0); } wrap() { if (this.pos.x > w) { this.pos.x = 0; } else if (this.pos.x < -this.fieldSize) { this.pos.x = w - 1; } if (this.pos.y > h) { this.pos.y = 0; } else if (this.pos.y < -this.fieldSize) { this.pos.y = h - 1; } } } class ParticleB { constructor(x, y) { this.pos = new Vector(x, y); this.vel = new Vector(Math.random() - 0.5, Math.random() - 0.5); this.acc = new Vector(0, 0); this.hue = Math.random()*30-15; this.rad = Math.random()*(particleSizeB - 5) + particleSizeB; } move(acc) { if (acc) { this.acc.addTo(acc); } this.vel.addTo(this.acc); this.pos.addTo(this.vel); if (this.vel.getLength() > maxSpeedB) { this.vel.setLength(maxSpeedB); } this.acc.setLength(0); } wrap() { if (this.pos.x > w) { this.pos.x = 0; } else if (this.pos.x < -this.fieldSize) { this.pos.x = w - 1; } if (this.pos.y > h) { this.pos.y = 0; } else if (this.pos.y < -this.fieldSize) { this.pos.y = h - 1; } } } canvas = document.querySelector("#canvas"); ctx = canvas.getContext("2d"); reset(); window.addEventListener("resize", reset); function initParticles() { particles = []; particlesB = []; for (let i = 0; i < particleCount; i++) { let particle = new Particle(Math.random() * w, Math.random() * h); particles.push(particle); } for (let i = 0; i < particleBCount; i++) { let particleB = new ParticleB(Math.random() * w, Math.random() * h); particlesB.push(particleB); } } function initField() { field = new Array(columns); fieldB = new Array(columns); for (let x = 0; x < columns; x++) { field[x] = new Array(rows); for (let y = 0; y < rows; y++) { let v = new Vector(0, 0); field[x][y] = v; } } } function calcField() { if (sORp) { for (let x = 0; x < columns; x++) { for (let y = 0; y < rows; y++) { let angle = noise.simplex3(x / 20, y / 20, noiseZ) * Math.PI * 2; let length = noise.simplex3(x / 40 + 40000, y / 40 + 40000, noiseZ) * fieldForce; field[x][y].setLength(length); field[x][y].setAngle(angle); } } } else { for (let x = 0; x < columns; x++) { for (let y = 0; y < rows; y++) { let angle = noise.perlin3(x / 20, y / 20, noiseZ) * Math.PI * 2; let length = noise.perlin3(x / 40 + 40000, y / 40 + 40000, noiseZ) * fieldForce; field[x][y].setLength(length); field[x][y].setAngle(angle); } } } } function reset() { w = canvas.width = window.innerWidth; h = canvas.height = window.innerHeight; //ctx.strokeStyle = fieldColor; noise.seed(Math.random()); columns = Math.round(w / fieldSize) + 1; rows = Math.round(h / fieldSize) + 1; initParticles(); initField(); } function draw() { requestAnimationFrame(draw); calcField(); noiseZ += noiseSpeed; drawBackground(); drawParticles(); } function drawBackground() { ctx.shadowBlur = 0; ctx.clearRect(0, 0, w, h); ctx.fillStyle = "rgba(0,0,0,1)"; ctx.fillRect(0, 0, w, h); } function drawParticles() { ctx.globalCompositeOperation = "lighter"; particlesB.forEach(p => { var ps = p.fieldSize = Math.abs(p.vel.x + p.vel.y) * p.rad; ctx.beginPath(); ctx.shadowBlur = 0; ctx.fillStyle = "hsl("+(hueBase + p.hue + ((p.vel.x + p.vel.y)*hueRange))+", 100%, 50%)"; ctx.arc(p.pos.x, p.pos.y, ps, 0, Math.PI * 2); ctx.fill(); ctx.closePath(); let pos = p.pos.div(fieldSize); let v; if (pos.x >= 0 && pos.x < columns && pos.y >= 0 && pos.y < rows) { v = field[Math.floor(pos.x)][Math.floor(pos.y)]; } p.move(v); p.wrap(); }); particles.forEach(p => { var ps = p.fieldSize = Math.abs(p.vel.x + p.vel.y) * p.rad; ctx.beginPath(); if(glow){ ctx.shadowBlur = p.rad; } ctx.shadowColor = "hsl("+(hueBase + p.hue + ((p.vel.x + p.vel.y)*hueRange))+", 100%, 50%)"; ctx.fillStyle = "hsl("+(hueBase + p.hue + ((p.vel.x + p.vel.y)*hueRange))+", 100%, 50%)"; ctx.arc(p.pos.x, p.pos.y, ps, 0, Math.PI * 2); ctx.fill(); ctx.closePath(); let pos = p.pos.div(fieldSize); let v; if (pos.x >= 0 && pos.x < columns && pos.y >= 0 && pos.y < rows) { v = field[Math.floor(pos.x)][Math.floor(pos.y)]; } p.move(v); p.wrap(); }); } draw();
粒子
时间
文字
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号