Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="canvas"></div>
<button class="btn-rain">make it rain!</button>
<button class="btn-gravity">invert gravity</button> 
Tip: Drag with your cursor to interact
              
            
!

CSS

              
                body {
  background: #1f2026;
  color: #D4D5D9;
  font-family: sans-serif;
}

              
            
!

JS

              
                const { Engine, Render, World, Bodies, Mouse, MouseConstraint } = Matter;

function rain() {
  const circles = [];
  for (i = 0; i < 40; i++) {
    const posX = 00 + Math.floor(Math.random() * Math.floor(200));
    const posY = -100 * i - 100;

    // alternate size and mass
    const radius = i % 2 === 0 ? 21 : 21.0 * 0.7;
    const bgScale = i % 2 === 0 ? 0.125 : 0.125 * 0.7;
    const mass = i % 2 === 0 ? 10 : 10 * 0.7;

    // create a circle
    const circle = Bodies.circle(posX, posY, radius, {
      force: { x: 0.1, y: 0 }, // slight posh to the right
      friction: 0.1, // looks cooler with less friction
      mass: 10,
      render: {
        sprite: {
          texture:
            "https://bitspeicher.blog/content/images/2017/11/bitspeicher-logo-1.png", // bitspeicher-Logo
          xScale: bgScale, // adjust background image size to circle size
          yScale: bgScale
        }
      }
    });
    circles.push(circle);
  }

  // add circles into the world
  World.add(engine.world, [...circles]);
}

function invertGravity(){
  engine.world.gravity.y = -engine.world.gravity.y;
}

// create an engine
const engine = Engine.create();

// create a renderer
const render = Render.create({
  element: document.querySelector(".canvas"),
  engine: engine,
  options: {
    width: 600,
    height: 600,
    wireframes: false,
    background: "#1e1e1e"
  }
});

// add mouse control
const mouse = Mouse.create(render.canvas),
  mouseConstraint = MouseConstraint.create(engine, {
    mouse: mouse,
    constraint: {
      stiffness: 0.5,
      render: {
        visible: false
      }
    }
  });

// create obstacles
const box1 = Bodies.rectangle(0, 500, 810, 60, {
  isStatic: true,
  angle: Math.PI * 0.06,
  friction: 0.01,
  render: { fillStyle: "#f6a477" }
});
const box2 = Bodies.rectangle(600, 300, 810, 60, {
  isStatic: true,
  angle: Math.PI * -0.06,
  friction: 0.01,
  render: { fillStyle: "#f6a477" }
});

// add all of the bodies to the world
World.add(engine.world, [box1, box2, mouseConstraint]);

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

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

// make it rain initially
rain();

// add button click event listeners
document.querySelector(".btn-rain").addEventListener("click", rain);
document.querySelector(".btn-gravity").addEventListener("click", invertGravity);

              
            
!
999px

Console