(function() { 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, Bounds = Matter.Bounds, Vector = Matter.Vector, Vertices = Matter.Vertices, MouseConstraint = Matter.MouseConstraint, Mouse = Matter.Mouse, Query = Matter.Query, Svg = Matter.Svg; Example.terrain = function(demo) { var engine = demo.engine, world = engine.world; world.bodies = []; var terrain; $.get('./svg/terrain.svg').done(function(data) { var vertexSets = [], color = Common.choose(['#556270', '#4ECDC4', '#C7F464', '#FF6B6B', '#C44D58']); $(data).find('path').each(function(i, path) { vertexSets.push(Svg.pathToVertices(path, 30)); }); terrain = Bodies.fromVertices(400, 350, vertexSets, { isStatic: true, render: { fillStyle: color, strokeStyle: color } }, true); World.add(world, terrain); var bodyOptions = { frictionAir: 0, friction: 0.0001, restitution: 0.6 }; World.add(world, Composites.stack(80, 100, 20, 20, 10, 10, function(x, y, column, row) { if (Query.point([terrain], { x: x, y: y }).length === 0) { return Bodies.polygon(x, y, 5, 12, bodyOptions); } })); }); var renderOptions = engine.render.options; renderOptions.showAngleIndicator = false; renderOptions.showVelocity = true; }; })();