Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
html, body { background: black; margin: 0; overflow: hidden; }
JavaScript
"use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var canvas = undefined, ctx = undefined; var count = 100; var particles = []; var screenPos = undefined, lastScreenPos = undefined; function setup() { canvas = createCanvas(windowWidth, windowHeight); ctx = canvas.drawingContext; colorMode(HSB, 255, 255, 255, 255); for (var i = 0; i < count; i++) { var p = new Particle(); p.randomize(); particles.push(p); } screenPos = createVector(screenX, screenY); lastScreenPos = screenPos.copy(); } function draw() { // background(0); fill(0, 20); rect(0, 0, width, height); stroke(255); noFill(); lastScreenPos = screenPos.copy(); screenPos = createVector(screenX, screenY); var screenForce = screenPos.copy().sub(lastScreenPos); var center = createVector(width / 2, height / 2); // let centerScreen = center.copy().add(screenForce); // line(center.x, center.y, centerScreen.x, centerScreen.y); screenForce.mult(0.1).limit(1); particles.forEach(function (n) { stroke((n.vel.heading() + PI) / TAU * 255, 255, 255); n.show(); var noiseForce = p5.Vector.fromAngle(map(noise(n.pos.x / 300, n.pos.y / 300, frameCount / 300), 0.3, 0.7, 0, TAU)); n.applyForce(screenForce); n.applyForce(noiseForce.limit(0.06)); n.update(); n.vel.limit(12); n.edges(); }); stroke(255, 40); var averageVelocity = particles.reduce(function (p, n) { return p.add(n.vel); }, createVector(0, 0)).div(particles.length); var centerAverageVelocity = center.copy().add(averageVelocity.mult(10)); line(center.x, center.y, centerAverageVelocity.x, centerAverageVelocity.y); } function windowResized() { resizeCanvas(windowWidth, windowHeight); } var Particle = function () { function Particle() { _classCallCheck(this, Particle); this.reset(); } Particle.prototype.applyForce = function applyForce() { var _acc; (_acc = this.acc).add.apply(_acc, arguments); }; Particle.prototype.reset = function reset() { this.pos = createVector(0, 0); this.acc = createVector(0, 0); this.vel = createVector(0, 0); }; Particle.prototype.randomize = function randomize() { this.pos.set(random(width), random(height)); }; Particle.prototype.update = function update() { this.vel.add(this.acc); this.acc.mult(0); this.pos.add(this.vel); this.vel.mult(0.99); }; Particle.prototype.edges = function edges() { if (this.pos.x < 0) this.pos.x += width;else if (this.pos.x > width) this.pos.x -= width; if (this.pos.y < 0) this.pos.y += height;else if (this.pos.y > height) this.pos.y -= height; }; Particle.prototype.show = function show() { var i = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; ellipse(this.pos.x, this.pos.y, 6); }; Particle.prototype.showVel = function showVel() { var pVel = this.pos.copy().add(this.vel); line(this.pos.x, this.pos.y, pVel.x, pVel.y); }; return Particle; }();
粒子
时间
文字
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号