Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
* { box-sizing: border-box; } html, body { margin: 0; }
JavaScript
// class Fluid class Fluid extends Entity { constructor(itteration, verly, config) { super(itteration, verly); this.config = config; this.init(); } init() { for (let i = 0; i < this.config.PARTICLES_COUNT; i++) { this.addFluid(); } } addFluid() { let p = new Point( random(this.verlyInstance.WIDTH), random(this.verlyInstance.HEIGHT) ).setRadius(5); this.addPoint(p).setColor(this.config.POINT_COLOR); } // fancy named function makeSurfaceTension() { this.sticks = []; for (let i = 0; i < this.points.length; i++) { for (let j = 0; j < this.points.length; j++) { let dist = this.points[i].pos.dist(this.points[j].pos); if (dist > 0 && dist < this.config.JOIN_DIST) { let s = this.addStick(i, j) .setStiffness(this.config.STIFFNESS) .setColor(this.config.LINE_COLOR); } } } } } let canvas = document.getElementById("c"); let ctx = canvas.getContext("2d"); let width = window.innerWidth - 4; let height = window.innerHeight - 4; canvas.width = width; canvas.height = height; function getPresetJSON() { return { preset: "Default", closed: false, remembered: { "Jelly Slime": { "0": { JOIN_DIST: 50, STIFFNESS: 0.02, GRAVITY: 1 } }, "Sticky Slime": { "0": { JOIN_DIST: 40, STIFFNESS: 0.4, GRAVITY: 0 } } } }; } // DAT.GUI CONFIGS let config = { PARTICLES_COUNT: 200, JOIN_DIST: 50, STIFFNESS: 0.02, GRAVITY: 1, POINT_COLOR: "#40ffa6", LINE_COLOR: "#1ba364" }; // GUI STUFF let gui = new dat.GUI({ load: getPresetJSON() }); gui.remember(config); let CountController = gui .add(config, "PARTICLES_COUNT", 10, 500) .name("Particles Count"); gui.add(config, "JOIN_DIST", 10, 200).name("Join Distance"); gui .add(config, "STIFFNESS", 0, 2) .step(0.01) .name("stiffness"); gui .add(config, "GRAVITY", -1, 1) .step(0.01) .name("gravity"); let PointColorController = gui .addColor(config, "POINT_COLOR") .name("Points Color"); let LineColorController = gui .addColor(config, "LINE_COLOR") .name("Stick Color"); PointColorController.onChange(value => { for (let p of fluid.points) { p.setColor(value); } }); LineColorController.onChange(value => { for (let s of fluid.sticks) { s.setColor(value); } }); CountController.onChange(() => { fluid.points = []; fluid.init(); }); // init verly let verly = new Verly(50, canvas, ctx); let fluid = new Fluid(50, verly, config); verly.addEntity(fluid); // resize window.onresize = function() { width = window.innerWidth - 4; height = window.innerHeight - 4; verly.WIDTH = canvas.width = width; verly.HEIGHT = canvas.height = height; }; function animate() { ctx.fillStyle = "#090909"; ctx.fillRect(0, 0, width, height); verly.update(); verly.render(); fluid.setGravity(new Vector(0, config.GRAVITY)); fluid.makeSurfaceTension(); // make all the points repel each other and also the Mouse for (let i = 0; i < fluid.points.length; i++) { // check for NaN and reset if (isNaN(fluid.points[i].pos.x) || isNaN(fluid.points[i].pos.y)) { fluid.points = []; fluid.init(); break; } fluid.points[i].resolveBehaviors({ pos: verly.mouse.coord }, 200, 15); for (let j = 0; j < fluid.points.length; j++) { fluid.points[j].resolveBehaviors( fluid.points[i], config.JOIN_DIST - 10, 10 ); fluid.points[i].resolveBehaviors( fluid.points[j], config.JOIN_DIST - 10, 10 ); } } requestAnimationFrame(animate); } animate();
粒子
时间
文字
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号