Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
* { box-sizing: border-box; margin: 0; padding: 0; } html, body { height: 100vh; width: 100%; } body { background: #ededed; overflow: hidden; } .support { position: absolute; right: 10px; bottom: 10px; padding: 10px; display: flex; z-index: 100; } .support a { margin: 0 10px; color: #fff; font-size: 1.8rem; backface-visibility: hidden; transition: all 150ms ease; } .support a:hover { transform: scale(1.1); }
JavaScript
console.clear(); class Particle { constructor(x, y, radius) { this.position = createVector(x, y); this.velocity = createVector(0, 0); this.acceleration = createVector(0, 0); this.maxspeed = 3; this.radius = radius; this.radiusDecrement = 1; } draw(s, f) { strokeWeight(0.8); stroke(s); fill(`${f}`); this.radius -= this.radiusDecrement; ellipse(this.position.x, this.position.y, this.radius); } update() { this.position.add(this.velocity); this.velocity.add(this.acceleration); this.acceleration.mult(0); this.velocity.limit(this.maxspeed); } applyForce(force) { this.acceleration.add(force); } follow(vectors) { let x = floor(this.position.x / scale); let y = floor(this.position.y / scale); let index = x + y * cols; let force = vectors[index]; this.applyForce(force); } } const GUI = new dat.GUI(); let settings = { types: { type_1: true, type_2: false, }, colorConfig: { whiteOnBlack: true, blackOnWhite: false, }, totalNumberOfParticles: 360, scale: 10, radius: { initial: 80, min: 20, max: 100, }, randomRadius: false, redraw: () => { resetAndInit(); }, save: () => { saveCanvas(canvas); }, }; let colorConfig = { background: "rgb(0,0,0)", stroke: 0, fill: "rgb(0,0,0)", }; let cols, scale, rows, particles = [], flowFields; let canvas; function setup() { canvas = createCanvas(innerWidth, innerHeight); resetAndInit(); } function init() { scale = settings.scale; cols = floor(width / scale) + 2; rows = floor(height / scale) + 2; flowFields = new Array(cols * rows); for (let i = 0; i < settings.totalNumberOfParticles; i++) { let x, y, radius; if (settings.types.type_1) { x = random(width); y = random(height); } if (settings.types.type_2) { x = Math.cos(i) * 100 + width / 2; y = Math.sin(i) * 100 + height / 2; } if (settings.randomRadius) { radius = randomIntegerFromRange(settings.radius.min, settings.radius.max); } else { radius = settings.radius.initial; } particles.push(new Particle(x, y, radius)); } } let increment = 0.1, start = 0, zoffset = 0, framecount = 0; function draw() { let xoffset = start; for (let x = 0; x < cols; x++) { let yoffset = start; for (let y = 0; y < rows; y++) { let index = x + y * cols; let angle = noise(xoffset, yoffset, zoffset) * TWO_PI * 2; let vector = p5.Vector.fromAngle(angle); flowFields[index] = vector; vector.setMag(1); yoffset += increment; } xoffset += increment; zoffset += 0.001; } particles.forEach(particle => { particle.update(); particle.follow(flowFields); if (!particle.radius <= 0) { particle.draw(Math.abs(colorConfig.stroke - framecount * 3), colorConfig.fill); } }); framecount++; } function windowResized() { resizeCanvas(innerWidth, innerHeight); resetAndInit(); } function resetCanvas() { background(`${colorConfig.background}`); framecount = 0; particles = []; } function resetAndInit() { resetCanvas(); init(); } function checkColorConfig() { if (settings.colorConfig.whiteOnBlack) { colorConfig.background = "rgb(0,0,0)"; colorConfig.fill = "rgb(0,0,0)"; colorConfig.stroke = 0; } if (settings.colorConfig.blackOnWhite) { colorConfig.background = "rgb(255,255,255)"; colorConfig.fill = "rgb(255,255,255)"; colorConfig.stroke = 255; } background(`${colorConfig.background}`); } // All dat.GUI Code ---------- let typesFolder = GUI.addFolder("Types"); addCheckbox(typesFolder, settings.types, "type_1", "Full"); addCheckbox(typesFolder, settings.types, "type_2", "circle"); let colorFolder = GUI.addFolder("Color Config"); addCheckbox(colorFolder, settings.colorConfig, "whiteOnBlack", "White On Black"); addCheckbox(colorFolder, settings.colorConfig, "blackOnWhite", "Black On White"); GUI.add(settings, "totalNumberOfParticles", 10, 360 * 2) .name("Particles") .onChange(resetAndInit); GUI.add(settings, "scale", 10, 50) .name("Scale") .onChange(resetAndInit); GUI.add(settings.radius, "initial", settings.radius.min, settings.radius.max) .step(10) .name("Radius") .onChange(resetAndInit); GUI.add(settings, "randomRadius") .name("Random Radius") .onChange(resetAndInit); GUI.add(settings, "redraw").name("RE-DRAW"); GUI.add(settings, "save").name("SAVE"); function addCheckbox(container, object, prop, name = prop) { container .add(object, prop) .name(name) .listen() .onChange(function() { setChecked(object, prop); resetAndInit(); checkColorConfig(); }); } // UTILS ---------- function setChecked(parameter, prop) { for (let param in parameter) { if (typeof param != Function || typeof param != Number) { parameter[param] = false; } } parameter[prop] = true; } function saveCanvas(canvas) { saveCanvas(canvas, "flowfield_art", "jpg"); } function randomIntegerFromRange(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); }
粒子
时间
文字
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号