matter+gsap实现重力感应下的无数个小球堆积交互动画效果代码

代码语言:html

所属分类:粒子

代码描述:matter+gsap实现重力感应下的无数个小球堆积交互动画效果代码

代码标签: matter gsap 重力 感应 无数 小球 堆积 交互 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  
  
<style>
.shapes {
  width:100vw;
  height: 100vh;
}

body {
  background: #e572b0;
  margin: 0;
}
</style>

  
</head>

<body translate="no">
  <div class="shapes"></div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/matter.0.19.0.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.10.1.js"></script>
      <script  >

const { Engine, Events, Body, Render, Bodies, World, MouseConstraint, Composites, Query, Common, Mouse } = Matter

var sectionTag = document.querySelector(".shapes");

//width and height of the area
let w =  sectionTag.offsetWidth;
let h = sectionTag.offsetHeight;

const engine = Engine.create();

 engine.world.gravity.x = 0  
 engine.world.gravity.y = 0.001 
 engine.world.gravity.scale = 0.1 

    var renderer = Render.create({
  element: sectionTag,
  engine: engine,
  options: {
    width: w,
    height: h,
    background: "transparent",
    wireframes: false,
    pixelRatio: window.devicePixelRatio
      }
    });
console.log(window.devicePixelRatio);

// Create a wall for the shapes to bounce off
const wallOptions = {
  isStatic: true,
  render: {
    visible: true,
    fillStyle: "#e572b0",
  },
  friction: 0,
  restitution: 1.1,
}

const ceiling = Bodies.rectangle(w / 2, -1, w, 50, wallOptions)
const ground = Bodies.rectangle(w / 2, h+50, w, 50, wallOptions)
const leftWall = Bodies.rectangle(-50, h / 2, 50, h, wallOptions)
const rightWall = Bodies.rectangle(w+50, h / 2, 50, h, wallOptions)

const mouseControl = MouseConstraint.create(engine, {
  element: sectionTag,
  constraint: {
    render: {
      visible: false
    }
  }
})


  

World.add(engine.world, [
  ground,
  ceiling,
  leftWall,
  rightWall,
 mouseControl,

]);

var color = "#9bc459";

// calculate number of circles based on window size
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0