matterjs

matterjs

by prodouga

HTML

<!DOCTYPE html>
<html lang="ja" >
<head>
  <meta charset="UTF-8">
  <title>MatterJS - Prodouga</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<div id="wrapper-canvas"></div>
  <!-- Codepen -->
  <div class="content">
    <h1 class="title">
      Prodouga
    </h1>
    <h2 class="subtitle">
      Hi, I'm a front-end engineer.
    </h2>
  </div>
  <div class="more-pens">
    <a target="_blank" href="https://www.prodouga.com/" class="white-mode white-mode--highlight">OFFICIAL</a>
    <a target="_blank" href="https://www.portfolio.prodouga.com" class="white-mode">PORTFOLIO</a>
    <a target="_blank" href="https://www.prodouga.com/contact" class="white-mode">CONTACT</a>
  </div>
<!-- partial -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.12.0/matter.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/matter-wrap@0.2.0/build/matter-wrap.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/matter-attractors@0.1.6/build/matter-attractors.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'></script><script  src="./script.js"></script>

</body>
</html>

CSS

@import url("https://fonts.googleapis.com/css?family=Catamaran:300,400,500,600,700");
body {
  padding: 0;
  margin: 0;
}

#wrapper-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #FFFFFF;
}

.more-pens {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  font-family: "Catamaran", sans-serif;
  font-size: 12px;
}

a.white-mode:link, a.white-mode:visited, a.white-mode:active {
  font-family: "Catamaran", sans-serif;
  font-size: 12px;
  text-decoration: none;
  background: #212121;
  padding: 8px 18px;
  color: #f7f7f7;
  border-radius: 20px;
  margin: 0 4px;
}
a.white-mode--highlight:link, a.white-mode--highlight:visited, a.white-mode--highlight:active {
  background: #293FE9;
}
a.white-mode:hover {
  background: #edf3f8;
  color: #212121;
}

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.content {
  -webkit-transform: translateY(-50%);
  -moz-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  -o-transform: translateY(-50%);
  transform: translateY(-50%);
  z-index: 10;
  position: absolute;
  left: 0;
  top: 50%;
  padding: 0 90px;
  text-align: left;
  pointer-events: none;
}

.title {
  font-family: "Catamaran", sans-serif;
  pointer-events: none;
  font-weight: 700;
  font-size: 70px;
  line-height: 1;
  margin-top: 14px;
  color: #212121;
  display: block;
  pointer-events: none;
}
.title span {
  color: #EC456C;
}

.subtitle {
  font-family: "Catamaran", sans-serif;
  pointer-events: none;
  font-weight: 300;
  font-size: 24px;
  line-height: 1;
  margin-top: 0;
  color: #212121;
  display: block;
  pointer-events: none;
}
.subtitle span {
  color: #EC456C;
}

.button {
  -webkit-transition: all 0.3s cubic-bezier(0.69, 0, 0.185, 1);
  transition: all 0.3s cubic-bezier(0.69, 0, 0.185, 1);
  border-radius: 30px;
  font-family: "Catamaran", sans-serif;
  font-size: 21px;
  font-style: normal;
  font-weight: 300;
  text-align: center;
  text-rendering:...

JavaScript

var canvas = $("#wrapper-canvas").get(0);

var dimensions = {
  width: $(window).width(),
  height: $(window).height() };


Matter.use('matter-attractors');
Matter.use('matter-wrap');

function runMatter() {
  // module aliases
  var Engine = Matter.Engine,
  Events = Matter.Events,
  Runner = Matter.Runner,
  Render = Matter.Render,
  World = Matter.World,
  Body = Matter.Body,
  Mouse = Matter.Mouse,
  Common = Matter.Common,
  Composite = Matter.Composite,
  Composites = Matter.Composites,
  Bodies = Matter.Bodies;

  // create engine
  var engine = Engine.create();

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

  // create renderer
  var render = Render.create({
    element: canvas,
    engine: engine,
    options: {
      showVelocity: false,
      width: dimensions.width,
      height: dimensions.height,
      wireframes: false,
      background: 'rgb(240,240,240)' } });



  // create runner
  var runner = Runner.create();

  // Runner.run(runner, engine);
  // Render.run(render);

  // create demo scene
  var world = engine.world;
  world.gravity.scale = 0;

  // create a body with an attractor
  var attractiveBody = Bodies.circle(
  render.options.width / 2,
  render.options.height / 2,
  Math.max(dimensions.width / 4, dimensions.height / 4) / 2,
  {
    render: {
      fillStyle: `rgb(240,240,240)`,
      strokeStyle: `rgb(240,240,240)`,
      lineWidth: 0 },

    isStatic: true,
    plugin: {
      attractors: [
      function (bodyA, bodyB) {
        return {
          x: (bodyA.position.x - bodyB.position.x) * 1e-6,
          y: (bodyA.position.y - bodyB.position.y) * 1e-6 };

      }] } });




  World.add(world, attractiveBody);

  // add some bodies that to be attracted
  for (var i = 0; i < 60; i += 1) {
    let x = Common.random(0, render.options.width);
    let y = Common.random(0, render.options.height);
    let s = Common.random() > 0.6 ? Common.random(10, 80) : Common.random(4, 60);
    let...