Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: rgb(0, 0, 0, .9); overflow: hidden }
JavaScript
const createParticleSystem = location => { const origin = location.copy(); const particles = []; const addParticle = velocity => { const rand = random(0, 1); if (rand <= .3) { particles.push(createSparkParticle(origin, velocity.copy())); } else { particles.push(createParticle(origin, velocity.copy())); } }; const applyForce = force => { particles.forEach(particle => { particle.applyForce(force); }); }; const run = () => { // ellipse(origin.x, origin.y, 10, 10); particles.forEach((particle, index) => { particle.move(); particle.draw(); if (particle.isDead()) { particles.splice(index, 1); } }); }; return { origin, addParticle, run, applyForce }; }; const createSparkParticle = (locationP, velocity) => { const particle = createParticle(locationP, velocity); let fade = 255; const draw = () => { colorMode(HSB); stroke(16, 62, 100, fade); const arrow = velocity.copy().normalize().mult(random(2, 4)); const direction = p5.Vector.add(particle.location, arrow); line(particle.location.x, particle.location.y, direction.x, direction.y); }; const move = () => { particle.applyForce(createVector(random(-.2, .2), random(-0.1, -0.4))); particle.velocity.add(particle.acc); particle.location.add(particle.velocity.copy().normalize().mult(random(2, 4))); particle.acc.mult(0); fade -= 5; }; return { ...particle, draw, move }; }; const createParticle = (locationP, velocity) => { const acc = createVector(0, 0); const location = locationP.copy(); let fade = 255; const fadeMinus = randomGaussian(15, 2); let ligther = 100; let situate = 62; const draw = () => { colorMode(HSB); stroke(16, constrain(situate, 62, 92), constrain(ligther, 60, 100), fade); const arrow = velocity.copy().mult(2); const direction = p5.Vector.add(location, arrow); line(location.x, location.y, direction.x, direction.y); }; const move = () => { velocity.add(acc); location.add(velocity.copy().div(map(velocity.mag(), 18, 0, 5, 1))); acc.mult(0); fade -= fadeMinus; ligther -= 8; situate += 8; }; const applyForce = force => { acc.add(force); }; const isDead = () => { if (fade < 0 || location.x < 0 || location.x > width || location.y > height) { return true; } else { return false; } }; return { draw, move, applyForce, isDead, velocity, location, acc }; }; const createMover = () => { const location = createVector(350, 250); const velocity = createVector(0, 0); const acc = createVector(0, 0); const mass = 10; let angle = 0; let angleVelocity = 0; let angleAcc = 0; let len = 100; const particleSystems = [ createParticleSystem(location), createParticleSystem(location), createParticleSystem(location), createParticleSystem(location), createParticleSystem(location), createParticleSystem(location), createParticleSystem(location), createParticleSystem(location), createParticleSystem(location)]; const getGotoVector = angle => { const radius = map(angleVelocity, 0, 0.3, 0, 100); const goToVector = createVector( location.x + radius * cos(angle), location.y + radius * sin(angle)); return goToVector; }; const draw = () => { const goToVector = getGotoVector(angle); particleSystems.forEach(particleSystem => { particleSystem.run(); }); }; const renderParticleSystem = () => { particleSystems.forEach(particleSystem => { const goToVector = getGotoVector(angle - Math.random(0, TWO_PI)); const prepencular = createVector( goToVector.y - location.y, (goToVector.x - location.x) * -1); prepencular.normalize(); prepencular.mult(angleVelocity * 70); particleSystem.origin.set(goToVector); particleSystem.addParticle(prepencular); const gravity = createVector(0, 0.3); particleSystem.applyForce(gravity); }); }; const move = () => { angleAcc = 0.001; angleVelocity = constrain(angleVelocity + angleAcc, 0, 0.32); angle += angleVelocity; angleAcc = 0; renderParticleSystem(); }; return { draw, move }; }; let mover; function setup() { createCanvas(700, 500); mover = createMover(); } function draw() { background(0); mover.move(); mover.draw(); }
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>p5.js粒子旋转效果-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号