<div class="visHolder">
  <svg id="svg" width="" height="" viewBox="" fill="none">
    <rect id="bg" x="0" y="0" width="" height="" />
    <path class="svgPath" d="M51.0619 87.7885H16.0665V68.6538H51.0619C57.156 68.6538 62.0806 67.6282 65.8356 65.5769C69.5906 63.5256 72.33 60.7051 74.0536 57.1154C75.8387 53.4615 76.7313 49.2949 76.7313 44.6154C76.7313 40.1923 75.8387 36.0577 74.0536 32.2115C72.33 28.3013 69.5906 25.1603 65.8356 22.7885C62.0806 20.4167 57.156 19.2308 51.0619 19.2308H23.1764V140H0V0H51.0619C61.4651 0 70.2986 1.92308 77.5623 5.76923C84.8877 9.55128 90.4586 14.8077 94.2752 21.5385C98.0917 28.2051 100 35.8333 100 44.4231C100 53.4615 98.0917 61.2179 94.2752 67.6923C90.4586 74.1667 84.8877 79.1346 77.5623 82.5962C70.2986 86.0577 61.4651 87.7885 51.0619 87.7885Z" fill="black" />
  </svg>
  <div id="rendererHolder">
  </div>
</div>
// this pen imports maatter.js from https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.12.0/matter.min.js
//https://cdn.jsdelivr.net/npm/poly-decomp-es@0.4.2/dist/poly-decomp-es.cjs.min.js
// https://cdn.jsdelivr.net/npm/pathseg@1.2.1/pathseg.min.js

// got info from https://www.youtube.com/watch?v=hZkah1Y85Oc&t=109s

const { Engine, Render, Bodies, World, Svg } = Matter;

// svg variables
const svg = document.querySelector("#svg");
const namespace = "http://www.w3.org/2000/svg";
const viewportWidth = 500;
const viewportHeight = 500;
const w = 500;
const h = 500;

// matterjs engine and runner
const engine = Engine.create();

// svg body
let svgBody, floor, leftwall, rightwall;
// svg graphic
let svgGraphic;
let wallThickness = 100;

function initSVG() {
  const svg = document.querySelector("svg");
  svg.setAttribute("width", `${viewportWidth}`);
  svg.setAttribute("height", `${viewportHeight}`);
  svg.setAttribute("viewBox", `0 0 ${w} ${h}`);
  
  const bg = document.querySelector("#bg");
  bg.setAttribute("width", `${w}`);
  bg.setAttribute("height", `${h}`);
  bg.setAttribute("fill", "#eaeaea");
}

function initRenderer() {
  // create renderer
  const rendererHolder = document.querySelector("#rendererHolder");
  const render = Render.create({
    element: rendererHolder,
    engine: engine,
    options: {
      width: w,
      height: h,
      showAngleIndicator: true
    }
  });

  Render.run(render);
}

function initParticle() {
  const svgPath = document.querySelector(".svgPath");
  const verticies = Matter.Svg.pathToVertices(svgPath);
  svgBody = Matter.Bodies.fromVertices(0, 0, [verticies], {
    restitution: 0.6,
    isStatic: false
  });
  
  const minX = svgBody.bounds.min.x;
  const minY = svgBody.bounds.min.y;

  console.log('bounds: ', svgBody.bounds)
  console.log("minX: ", minX);
  console.log("minY: ", minY);
  console.log(minX,minY);

  svgGraphic = document.createElementNS(namespace, "g");
  svgGraphic.appendChild(svgPath);
  svgPath.setAttribute("transform", `translate(${minX} ${minY})`);

  svg.appendChild(svgGraphic);

  Matter.Body.setPosition(svgBody, { x: w/2, y: 0 });
  Matter.Body.setAngle(svgBody, Math.random() * 2 * Math.PI);
}

function makeBoundaries() {
  floor = Bodies.rectangle(w/2, h+wallThickness/2, w, wallThickness, {
    isStatic: true,
    id: "floor"
  });

  leftwall = Bodies.rectangle(-50, h/2, wallThickness, h, {
    isStatic: true,
    id: "leftwall"
  });

  rightwall = Bodies.rectangle(w + wallThickness, h/2, wallThickness, h, {
    isStatic: true,
    id: "righttwall"
  });
}

function makeWorld() {
  World.add(engine.world, [svgBody, floor, leftwall, rightwall]);
}

function update() {
  Engine.update(engine);
  const degrees = (svgBody.angle * 180) / Math.PI;
  svgGraphic.setAttribute(
    "transform",
    `translate(${svgBody.position.x}, ${svgBody.position.y}) rotate(${degrees})`
  );

  window.requestAnimationFrame(update);
}

initSVG();
initRenderer();
initParticle();
makeBoundaries();
makeWorld();
update();
Run Pen

External CSS

  1. https://codepen.io/aokorodu/pen/poBNOgp.css

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.12.0/matter.min.js
  2. https://cdn.jsdelivr.net/npm/poly-decomp-es@0.4.2/dist/poly-decomp-es.cjs.min.js
  3. https://cdn.jsdelivr.net/npm/pathseg@1.2.1/pathseg.min.js