Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                
              
            
!

CSS

              
                body {
  text-align: center;
  margin: 10px;
  font-family: 'Lato';
  background: #FBFBFB;
}

canvas {
  margin: 20px auto;
}

button {
  color: white;
  background: orange;
  border: none;
  padding: 10px;
  font-weight: 300;
  font-size: 1.2em;
  font-family: 'Lato';
  margin: 10px;
  cursor: pointer;
  outline: none;
}
              
            
!

JS

              
                const Engine = Matter.Engine;
const Render = Matter.Render;
const Composites = Matter.Composites;
const MouseConstraint = Matter.MouseConstraint;
const Mouse = Matter.Mouse;
const World = Matter.World;
// const Constraint = Matter.Constraint;
const Bodies = Matter.Bodies;
const Body = Matter.Body;

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

// create renderer
const render = Render.create({
  element: document.body,
  engine: engine,
  options: {
    width: 920,
    height: 600,
    wireframes: false,
  }
});

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

// keep the mouse in sync with rendering
// render.mouse = mouse;

Engine.run(engine);
Render.run(render);

const nameBlock = [
  [7, 8, 9, 10, 'A', 13, 14, 15, 16, 17, 'R', 20, 26, 'V', 28, 29, 30, 31, 32, 'I', 34, 35, 39, 'N'],
  [6, 11, 'A', 13, 18, 'R', 20, 26, 'V', 30, 'I', 34, 35, 36, 39, 'N'],
  [6, 11, 'A', 13, 17, 18, 'R', 20, 26, 'V', 30, 'I', 34, 36, 37, 39, 'N'],
  [6, 7, 8, 9, 10, 11, 'A', 13, 16, 17, 'R', 20, 26, 'V', 30, 'I', 34, 37, 38, 39, 'N'],
  [6, 11, 'A', 13, 15, 16, 'R', 21, 25, 'V', 30, 'I', 34, 38, 39, 'N'],
  [6, 11, 'A', 13, 16, 17, 'R', 22, 24, 'V', 30, 'I', 34, 39, 'N'],
  [6, 11, 'A', 13, 17, 18, 'R', 23, 'V', 28, 29, 30, 31, 32, 'I', 34, 39, 'N'],
];

const static = (x, y) => {
  const indexX = (x - 125) / 15;
  const indexY = (y - 15) / 15;
  const block = nameBlock[indexY];
  if (block && block.indexOf(indexX) !== -1) {
    return [true, ['#229A3B', '#196126']];
  }
  return [false, ['#EBEDEF', '#C5E48B']];
};

const stack = Composites.stack(125, 15, 45, 7, 0, 0, function(x, y) {
  const [isStatic, color] = static(x, y);
  
  const block = Bodies.rectangle(x, y, 15, 15, {
    render: {
      fillStyle: color[~~(Math.random() * 2)],
      strokeStyle: '#fff',
    },
    frictionAir: 0.03,
  });
  setTimeout(() => {
    Body.setStatic(block, isStatic);
  }, 800);
  setTimeout(() => {
    Body.set(block, { frictionAir: 0 });
  }, 600);
  setTimeout(() => {
    if (!isStatic) {
      Body.setVelocity(block, {x: 3, y: -10});
    }
  }, 900);
  return block;
});

const wallOption = {
  render: {
    fillStyle: 'transparernt',
    strokeStyle: '#FBFBFB',
  },
  isStatic: true,
};

const topWall = Bodies.rectangle(450, 0, 650, 30, wallOption);
const bottomWall = Bodies.rectangle(450, 500, 600, 30, wallOption);
const rightWall = Bodies.rectangle(880, 10, 30, 420, wallOption);
const leftWall = Bodies.rectangle(110, 10, 30, 420, wallOption);

World.add(world, [
  stack,
  // walls
  topWall,
  bottomWall,
  rightWall,
  leftWall
]);


              
            
!
999px

Console