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

              
                <div id="canvas-container"></div>
 </div>
              
            
!

CSS

              
                body { 
    background: #8dd;
    text-align: center;
}

canvas {
    margin: 0;
    max-height:100%;
    max-width:100%;
    border-radius: 3px;
}

canvas:active { 
    cursor: pointer;
    cursor: -webkit-grabbing;
}

#canvas-container {
    margin: 0px 0;
}
              
            
!

JS

              
                (function() {

    // Matter aliases
    var Engine = Matter.Engine,
        World = Matter.World,
        Bodies = Matter.Bodies,
        Body = Matter.Body,
        Composite = Matter.Composite,
        Composites = Matter.Composites,
        Common = Matter.Common,
        Constraint = Matter.Constraint,
        Events = Matter.Events;

    var Demo = {};

    var _engine,
        _sceneName;
  
      Body.create = function(options) {
        var defaults = {
            id: Body.nextId(),
            angle: 0,
            position: { x: 0, y: 0 },
            force: { x: 0, y: 0 },
            torque: 0,
            positionImpulse: { x: 0, y: 0 },
            speed: 0,
            angularSpeed: 0,
            velocity: { x: 0, y: 0 },
            angularVelocity: 0,
            isStatic: false,
            isSleeping: false,
            motion: 1,
            sleepThreshold: 60,
            density: 0.001,
            restitution: 0,
            friction: 0.01,
            frictionAir: 0.3,
            path: 'L 0 0 L 40 0 L 40 40 L 0 40',
            fillStyle: options.isStatic ? 'rgba(255,255,255,1.0)' : Common.choose(['#EACDCD', '#75394D', '#402E2B', '#57734A', '#BFBF56']),
            strokeStyle:'rgba(25,25,25,0.0)',
            strokeWidth: 0,
            lineWidth: 0,
            groupId: 0,
            slop: 0.0
        };

        var body = Common.extend(defaults, options);

        Body.updateProperties(body);

        return body;
    };
    
    Demo.init = function() {
        var container = document.getElementById('canvas-container');

        // engine options - these are the defaults
        var options = {
            positionIterations: 6,
            velocityIterations: 6,
            enableSleeping: false,
            timeScale: 1
        };

        // create a Matter engine, with the element to insert the canvas into
        // NOTE: this is actually Matter.Engine.create(), see the aliases at top of this file
        _engine = Engine.create(container, options);

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

        // default scene function name
        _sceneName = 'avalanche';
        
        // get the scene function name from hash
        if (window.location.hash.length !== 0) 
            _sceneName = window.location.hash.replace('#', '');

        // set up a scene with bodies
        Demo[_sceneName]();
    };

    if (window.addEventListener) {
        window.addEventListener('load', Demo.init);
    } else if (window.attachEvent) {
        window.attachEvent('load', Demo.init);
    }
    
    Demo.avalanche = function() {
        var _world = _engine.world;
        
       //Demo.reset();
        _engine.enableSleeping = false;
        _engine.world.gravity.y = 1.5;
      
        var renderOptions = _engine.render.options;
        renderOptions.wireframes = false;        
        renderOptions.background = 'rbg(255,255,234)';

        var offset = 5;
        World.addBody(_world, Bodies.rectangle(400, 600 + offset, 800.5 + 2 * offset, 50.5, { isStatic: true }));
        World.addBody(_world, Bodies.rectangle(800 + offset, 300, 50.5, 600.5 + 2 * offset, { isStatic: true }));
        World.addBody(_world, Bodies.rectangle(-offset, 300, 50.5, 600.5 + 2 * offset, { isStatic: true }));
        
      
        var stack = Composites.stack(300, 10, 4, 10, 0, 0, function(x, y, column, row) {
            return Bodies.polygon(x, y, 8,25,{
                                        render: {
                                          sprite: {
                                            texture: 'http://mixsandwich.info/js/sakura.png'
                                          }
                                        }
            });
        });
        
        World.addComposite(_world, stack);
        
        World.addBody(_world, Bodies.polygon(400, 300, 5, 50, { isStatic : true}));

    };
  
})();
              
            
!
999px

Console