matter实现气泡重力模拟碰撞交互动画效果代码
代码语言:html
所属分类:动画
代码描述:matter实现气泡重力模拟碰撞交互动画效果代码,点击空白处创建气泡。
代码标签: matter 气泡 重力 模拟 碰撞 交互 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap'); * { box-sizing: border-box; } body { margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; color: #fff; background: #222; } canvas { opacity: 0.9; background: transparent !important; } </style> </head> <body> 👌 💥Click space to create bubble. 👆 Hover to turn bubble black. 💣 Drag bubble to hit other bubbles. <section class="canvas"></section> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/matter.0.19.0.js"></script> <script > /* --- System Parameters (Recommended)--- */ let pBounce = 0.8; // Define Bounciness (0.8) let pFriction = 0.01; // Define air friction (0.01) // mouse click in mid-air to create more particles /* --- Main Program: DO NOT EDIT BELOW --- */ let w = window.innerWidth; let h = window.innerHeight; const { Engine, Render, Bodies, World, MouseConstraint, Composites, Query } = Matter; const sectionTag = document.querySelector("section.canvas"); const engine = Engine.create(); const renderer = Render.create({ element: sectionTag, engine: engine, options: { width: w, height: h, background: "#000000", wireframes: false, pixelRatio: window.devicePixelRatio } }); // Create a bubble const createShape = function (x, y) { return Bodies.circle(x, y, 25, { frictionAir: pFriction, restitution: pBounce, render: { sprite: { yScale: 0.5, xScale: 0.5 } } }); }; // Create a static body to bounce off const staticObj = Bodies.polygon(w / 2, h / 2, 6, Math.min(w / 6, h / 6), { isStatic: true, render: { lineWidth: 5, strokeStyle: 'yellow', fillStyle: "#448", visible: true } }); // Create a wall for the shapes to bounce off const wa.........完整代码请登录后点击上方下载按钮下载查看
网友评论0