css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="title">
  <h1><span>Hi & Welcome!</span></h1>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Montserrat:200,300,400,600')
.more-pens
  position: fixed
  left: 20px
  bottom: 20px
  z-index: 10
  font-family: "Montserrat"
  font-size: 12px

a.white-mode, a.white-mode:link, a.white-mode:visited, a.white-mode:active
  font-family: "Montserrat"
  font-size: 12px
  text-decoration: none
  background: #212121
  padding: 4px 8px
  color: #f7f7f7
  &:hover
    background: #edf3f8
    color: #212121

body
  margin: 0
  padding: 0
  overflow: hidden
  width: 100%
  height: 100%
  background: #EFEFEF

  
.title
  z-index: 10
  position: absolute
  left: 50%
  top: 50%
  transform: translateX(-50%) translateY(-50%)
  font-family: "Montserrat"
  text-align: center
  width: 100%
  h1
    position: relative
    color: #121212
    font-weight: 600
    font-size: 60px
    padding: 0
    margin: 0
    line-height: 1

    span
      font-weight: 600
      padding: 0
      margin: 0
      color: #BBB

  h3
    font-weight: 200
    font-size: 20px
    padding: 0
    margin: 0
    line-height: 1
    color: #121212
    letter-spacing: 2px
            
          
!
            
              let Engine = Matter.Engine,
    Render = Matter.Render,
    World = Matter.World,
    Mouse = Matter.Mouse,
    Bodies = Matter.Bodies,
    Common = Matter.Common,
    Vertices = Matter.Vertices,
    Svg = Matter.Svg,
    Constraint = Matter.Constraint,
    Composites = Matter.Composites,
    MouseConstraint = Matter.MouseConstraint;

  // create an engine
  let engine = Engine.create();
  let idRAF = null;
function init(){
  let numm = Math.random();
  $("canvas").remove();
  
  cancelAnimationFrame(idRAF);
  let width = $(window).width();
  let height = $(window).height();
  let offset = -1;
    // module aliases
  
  engine.events = {};
  World.clear(engine.world);
  Engine.clear(engine);
  
  engine = Engine.create();

  engine.world.gravity.x = 0;
  engine.world.gravity.y = 0;
  let mouseConstraint = MouseConstraint.create(engine);
  World.add(engine.world, mouseConstraint);

  // create a renderer
  let render = Render.create({
    element: document.body,
    engine: engine,
    options: {
      wireframes: false,
      background: 'transparent',
      width: width,
      height: height,
      showDebug: false,
      showBroadphase: false,
      showBounds: false,
      showVelocity: false,
      showCollisions: false,
      showSeparations: false,
      showAxes: false,
      showPositions: false,
      showAngleIndicator: false,
      showIds: false,
      showShadows: false,
      showVertexNumbers: false,
      showConvexHulls: false,
      showInternalEdges: false,
      showMousePosition: false
    }
  });

  // create two boxes and a ground
  // add all of the bodies to the world
  World.add(engine.world, [
    Bodies.rectangle(width / 2, height / 2, 500, 46, {
      isStatic: true,
      render: {
        fillStyle: "transparent"
      }
    }),
    
    Bodies.rectangle(width / 2, (height / 2) - 40, 180, 20, {
      isStatic: true,
      render: {
        fillStyle: "transparent"
      }
    }),
    Bodies.rectangle(width / 2, (height / 2) + 40, 180, 20, {
      isStatic: true,
      render: {
        fillStyle: "transparent"
      }
    }),
    Bodies.rectangle(width / 2, height - offset, width, 1, {
      isStatic: true,
      render: {
        fillStyle: "#FFFFFF"
      }
    }),
    Bodies.rectangle(width / 2, offset, width, 1, {
      isStatic: true,
      render: {
        fillStyle: "#FFFFFF"
      }
    }),
    Bodies.rectangle(offset, height / 2, 1, height, {
      isStatic: true,
      render: {
        fillStyle: "#FFFFFF"
      }
    }),
    Bodies.rectangle(width - offset, height / 2, 1, height, {
      isStatic: true,
      render: {
        fillStyle: "#FFFFFF"
      }
    })
  ]);

  for (let i = 0; i < 230; i++) {
    let radius = 2 + Math.random() * 20
    World.add(engine.world, Bodies.circle(
      40 + Math.random() * width - 80,
      40 + Math.random() * 100,
      radius, {
        render: {
          fillStyle: ["#4285F4", "#EA4335", "#FBBC05", "#34A853"][Math.round(Math.random() * 3)]
        }

      }
    ))
  }


  // run the engine
  Engine.run(engine);

  // run the renderer
  Render.run(render);

  let inc = 0

  engine.world.gravity.y = 4
  function update() {
    if(inc > 8){
      engine.world.gravity.x = Math.cos(inc / 55)
      engine.world.gravity.y = Math.sin(inc / 55)
    }
    inc++
    idRAF = requestAnimationFrame(update.bind(this))
  }

  update()
}
init()

function debounce(func, wait, immediate) {
	var timeout;
	return function() {
		var context = this, args = arguments;
		var later = function() {
			timeout = null;
			if (!immediate) func.apply(context, args);
		};
		var callNow = immediate && !timeout;
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
		if (callNow) func.apply(context, args);
	};
};


$(window).on("resize", debounce(function(){
  init()
}.bind(this), 200))
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console