// Matter.js - http://brm.io/matter-js/ // Matter module aliases var Engine = Matter.Engine, World = Matter.World, Body = Matter.Body, Bodies = Matter.Bodies, Common = Matter.Common, Composites = Matter.Composites, MouseConstraint = Matter.MouseConstraint; // create a Matter.js engine var engine = Engine.create(document.body, { render: { options: { showAngleIndicator: true, wireframes: true } } }); // add a mouse controlled constraint var mouseConstraint = MouseConstraint.create(engine); World.add(engine.world, mouseConstraint); // create a load of circle bodies var stack1 = Composites.stack(5, 290, 25, 3, 0, 0, function(x, y, column, row) { return Bodies.circle(x, y, Common.random(2, 36), { friction: 0.001, restitution: 0.01, density: 5.2 }); }); var stack2 = Composites.stack(30, 20, 25, 15, 5, 5, function(x, y, column, row) { return Bodies.circle(x, y, Common.random(0.1, 20), { friction: 0.0005, restitution: 0.001, density: 2.1 }); }); // add circle bodies to the world //World.add(engine.world, stack1 ); World.add(engine.world, stack2 ); // add some ramps to the world for the bodies to roll down World.add(engine.world, [ Bodies.rectangle(100, 260, 600, 20, { isStatic: true, angle: Math.PI * 0.04 }), // Bodies.rectangle(500, 350, 700, 20, { isStatic: true, angle: -Math.PI * 0.06 }), // Bodies.rectangle(340, 580, 700, 20, { isStatic: true, angle: Math.PI * 0.04 }) ]); // add some some walls to the world var offset = 5; World.add(engine.world, [ Bodies.rectangle(400, -offset, 800 + 2 * offset, 50, { isStatic: true }), Bodies.rectangle(400, 600 + offset, 800 + 2 * offset, 50, { isStatic: true }), Bodies.rectangle(800 + offset, 300, 50, 600 + 2 * offset, { isStatic: true }), Bodies.rectangle(-offset, 300, 50, 600 + 2 * offset, { isStatic: true }) ]); var renderOptions = engine.render.options; //renderOptions.showBroadphase = true; // run the engine Engine.run(engine); engine.timing.timeScale =0.85 //engine.enableSleeping = true;