Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html, body { margin: 0; padding: 0; height: 100%; } body { background-color:black; display: flex; align-items: center; justify-content: center; overflow: hidden; }
JavaScript
class Particle { constructor(origin) { this.origin = origin; this.init(); } init(){ this.position = createVector(this.origin.x,this.origin.y); this.velocity = p5.Vector.fromAngle(random(0,TWO_PI)).mult(random(0.1,2)); this.acc = createVector(0,0); this.size = random(10,80); this.wiggle_speed = map(this.size,20,80,0.4,0.1); this.wiggle_factor = map(this.size,20,80,0.2,16); this.lift = createVector(0,-random(0.001,0.04)); this.duration = random(10,200); this.start = frameCount; this.random_index = random(0,100); this.max_opacity = random(10,100); this.max_speed = random(4,10); // trail this.trail = []; let trail_length = floor(random(6,40)); for(let i = 0; i < trail_length; i++){ this.trail.push({ x:this.position.x, y:this.position.y, start:frameCount-i, duration:trail_length-1 }); } } display(index) { // let current = frameCount - this.start; // Apply Forces this.addForce(this.lift); // this.velocity.add(this.acc); this.velocity.limit(this.max_speed); this.position.add(this.velocity); this.acc.mult(0); // Wiggle let angle = this.velocity.heading() + Math.PI/2; let wiggle = Math.sin((this.random_index + frameCount) * this.wiggle_speed) * this.wiggle_factor; wiggle *= map(this.velocity.mag(),0,this.max_speed*0.4,0.2,1); let w_x = this.position.x + Math.cos(angle) * wiggle, w_y = this.position.y + Math.sin(angle) * wiggle; let size_percent; if(this.duration - current < this.duration * 0.5){ size_percent = map(constrain(this.duration - current,0,this.duration),0,this.duration,0,1); }else{ size_percent = map(constrain(this.duration - current,0,this.duration),0,this.duration,1,0); } if(current > this.duration){ this.init(); }else{ let c = color( map(this.velocity.mag(),0,this.max_speed,200,0), 180, 255, map(this.velocity.mag(),0,this.max_speed,0,this.max_opacity) ); fill(c); this.trail.forEach(t=>{ let c = frameCount - t.start; if(c > t.duration){ t.x = w_x; t.y = w_y; t.start = frameCount; } let decay = map(constrain(t.duration - c,0,t.duration),0,t.duration,0,1); circle(t.x,t.y,this.size*decay*size_percent); }); } } addForce(vector){ this.acc.add(vector); } } let p_stock = []; let gravity, origin; function setup() { createCanvas(480, 480); origin = createVector(width/2,height*0.8); gravity = createVector(0,0.2); for (let i = 0; i < 140; i++) { p_stock.push(new Particle(origin)); } colorMode(HSB, 255); noStroke(); } function draw() { blendMode(BLEND); background(0,60); blendMode(ADD); p_stock.forEach((p,index) => { p.display(index); }); }
粒子
时间
文字
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号