From f9ea7995bfb0e08b3a78c8c595dc708bb47bbb4b Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 14 Sep 2019 18:54:50 +0100 Subject: [PATCH] added module export to examples --- examples/airFriction.js | 6 ++- examples/avalanche.js | 6 ++- examples/ballPool.js | 6 ++- examples/bridge.js | 6 ++- examples/broadphase.js | 6 ++- examples/car.js | 6 ++- examples/catapult.js | 6 ++- examples/chains.js | 6 ++- examples/circleStack.js | 6 ++- examples/cloth.js | 6 ++- examples/collisionFiltering.js | 6 ++- examples/compositeManipulation.js | 6 ++- examples/compound.js | 6 ++- examples/compoundStack.js | 6 ++- examples/concave.js | 6 ++- examples/constraints.js | 6 ++- examples/doublePendulum.js | 6 ++- examples/events.js | 6 ++- examples/friction.js | 6 ++- examples/gravity.js | 6 ++- examples/gyro.js | 48 ++++++++++++--------- examples/index.js | 45 +++++++++++++++++++ examples/manipulation.js | 6 ++- examples/mixed.js | 6 ++- examples/newtonsCradle.js | 6 ++- examples/pyramid.js | 6 ++- examples/ragdoll.js | 6 ++- examples/raycasting.js | 6 ++- examples/restitution.js | 6 ++- examples/rounded.js | 6 ++- examples/sensors.js | 6 ++- examples/sleeping.js | 6 ++- examples/slingshot.js | 6 ++- examples/softBody.js | 6 ++- examples/sprites.js | 6 ++- examples/stack.js | 6 ++- examples/staticFriction.js | 6 ++- examples/stress.js | 6 ++- examples/stress2.js | 6 ++- examples/svg.js | 72 +++++++++++++++++-------------- examples/terrain.js | 64 ++++++++++++++------------- examples/timescale.js | 6 ++- examples/views.js | 6 ++- examples/wreckingBall.js | 6 ++- 44 files changed, 347 insertions(+), 122 deletions(-) create mode 100644 examples/index.js diff --git a/examples/airFriction.js b/examples/airFriction.js index b1bc08a..bcac6ff 100644 --- a/examples/airFriction.js +++ b/examples/airFriction.js @@ -78,4 +78,8 @@ Example.airFriction = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/avalanche.js b/examples/avalanche.js index eb04452..053387f 100644 --- a/examples/avalanche.js +++ b/examples/avalanche.js @@ -89,4 +89,8 @@ Example.avalanche = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/ballPool.js b/examples/ballPool.js index 11ad322..252873f 100644 --- a/examples/ballPool.js +++ b/examples/ballPool.js @@ -97,4 +97,8 @@ Example.ballPool = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/bridge.js b/examples/bridge.js index 78b24ad..7e9ca5f 100644 --- a/examples/bridge.js +++ b/examples/bridge.js @@ -122,4 +122,8 @@ Example.bridge = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/broadphase.js b/examples/broadphase.js index cc6decf..87ca466 100644 --- a/examples/broadphase.js +++ b/examples/broadphase.js @@ -93,4 +93,8 @@ Example.broadphase = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/car.js b/examples/car.js index 215f47d..7aa56a5 100644 --- a/examples/car.js +++ b/examples/car.js @@ -87,4 +87,8 @@ Example.car = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/catapult.js b/examples/catapult.js index 6c08996..f982be7 100644 --- a/examples/catapult.js +++ b/examples/catapult.js @@ -94,4 +94,8 @@ Example.catapult = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/chains.js b/examples/chains.js index fbaf358..fe6aae1 100644 --- a/examples/chains.js +++ b/examples/chains.js @@ -120,4 +120,8 @@ Example.chains = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/circleStack.js b/examples/circleStack.js index e318756..cbc9917 100644 --- a/examples/circleStack.js +++ b/examples/circleStack.js @@ -79,4 +79,8 @@ Example.circleStack = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/cloth.js b/examples/cloth.js index 5cbc6f0..1fa521b 100644 --- a/examples/cloth.js +++ b/examples/cloth.js @@ -82,4 +82,8 @@ Example.cloth = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/collisionFiltering.js b/examples/collisionFiltering.js index f9185ed..9671782 100644 --- a/examples/collisionFiltering.js +++ b/examples/collisionFiltering.js @@ -153,4 +153,8 @@ Example.collisionFiltering = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/compositeManipulation.js b/examples/compositeManipulation.js index 77737c5..aa30114 100644 --- a/examples/compositeManipulation.js +++ b/examples/compositeManipulation.js @@ -105,4 +105,8 @@ Example.compositeManipulation = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/compound.js b/examples/compound.js index 7b6205b..5cbb8b3 100644 --- a/examples/compound.js +++ b/examples/compound.js @@ -104,4 +104,8 @@ Example.compound = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/compoundStack.js b/examples/compoundStack.js index 8462ee0..f5ff325 100644 --- a/examples/compoundStack.js +++ b/examples/compoundStack.js @@ -87,4 +87,8 @@ Example.compoundStack = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/concave.js b/examples/concave.js index f661d7f..c7acf86 100644 --- a/examples/concave.js +++ b/examples/concave.js @@ -93,4 +93,8 @@ Example.concave = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/constraints.js b/examples/constraints.js index 23eca4a..653033f 100644 --- a/examples/constraints.js +++ b/examples/constraints.js @@ -177,4 +177,8 @@ Example.constraints = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/doublePendulum.js b/examples/doublePendulum.js index 468193e..b5744ea 100644 --- a/examples/doublePendulum.js +++ b/examples/doublePendulum.js @@ -150,4 +150,8 @@ Example.doublePendulum = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/events.js b/examples/events.js index 961cafe..cad6e18 100644 --- a/examples/events.js +++ b/examples/events.js @@ -176,4 +176,8 @@ Example.events = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/friction.js b/examples/friction.js index f3b92a8..e4a3d24 100644 --- a/examples/friction.js +++ b/examples/friction.js @@ -88,4 +88,8 @@ Example.friction = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/gravity.js b/examples/gravity.js index 9751e3c..5266645 100644 --- a/examples/gravity.js +++ b/examples/gravity.js @@ -94,4 +94,8 @@ Example.gravity = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/gyro.js b/examples/gyro.js index d8c1711..364ef7a 100644 --- a/examples/gyro.js +++ b/examples/gyro.js @@ -68,26 +68,28 @@ Example.gyro = function() { ]); // add gyro control - var updateGravity = function(event) { - var orientation = typeof window.orientation !== 'undefined' ? window.orientation : 0, - gravity = engine.world.gravity; + if (typeof window !== 'undefined') { + var updateGravity = function(event) { + var orientation = typeof window.orientation !== 'undefined' ? window.orientation : 0, + gravity = engine.world.gravity; - if (orientation === 0) { - gravity.x = Common.clamp(event.gamma, -90, 90) / 90; - gravity.y = Common.clamp(event.beta, -90, 90) / 90; - } else if (orientation === 180) { - gravity.x = Common.clamp(event.gamma, -90, 90) / 90; - gravity.y = Common.clamp(-event.beta, -90, 90) / 90; - } else if (orientation === 90) { - gravity.x = Common.clamp(event.beta, -90, 90) / 90; - gravity.y = Common.clamp(-event.gamma, -90, 90) / 90; - } else if (orientation === -90) { - gravity.x = Common.clamp(-event.beta, -90, 90) / 90; - gravity.y = Common.clamp(event.gamma, -90, 90) / 90; - } - }; + if (orientation === 0) { + gravity.x = Common.clamp(event.gamma, -90, 90) / 90; + gravity.y = Common.clamp(event.beta, -90, 90) / 90; + } else if (orientation === 180) { + gravity.x = Common.clamp(event.gamma, -90, 90) / 90; + gravity.y = Common.clamp(-event.beta, -90, 90) / 90; + } else if (orientation === 90) { + gravity.x = Common.clamp(event.beta, -90, 90) / 90; + gravity.y = Common.clamp(-event.gamma, -90, 90) / 90; + } else if (orientation === -90) { + gravity.x = Common.clamp(-event.beta, -90, 90) / 90; + gravity.y = Common.clamp(event.gamma, -90, 90) / 90; + } + }; - window.addEventListener('deviceorientation', updateGravity); + window.addEventListener('deviceorientation', updateGravity); + } // add mouse control var mouse = Mouse.create(render.canvas), @@ -121,7 +123,13 @@ Example.gyro = function() { stop: function() { Matter.Render.stop(render); Matter.Runner.stop(runner); - window.removeEventListener('deviceorientation', updateGravity); + if (typeof window !== 'undefined') { + window.removeEventListener('deviceorientation', updateGravity); + } } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/index.js b/examples/index.js new file mode 100644 index 0000000..1894b72 --- /dev/null +++ b/examples/index.js @@ -0,0 +1,45 @@ +module.exports = { + airFriction: require('./airFriction.js'), + avalanche: require('./avalanche.js'), + ballPool: require('./ballPool.js'), + bridge: require('./bridge.js'), + broadphase: require('./broadphase.js'), + car: require('./car.js'), + catapult: require('./catapult.js'), + chains: require('./chains.js'), + circleStack: require('./circleStack.js'), + cloth: require('./cloth.js'), + collisionFiltering: require('./collisionFiltering.js'), + compositeManipulation: require('./compositeManipulation.js'), + compound: require('./compound.js'), + compoundStack: require('./compoundStack.js'), + concave: require('./concave.js'), + constraints: require('./constraints.js'), + doublePendulum: require('./doublePendulum.js'), + events: require('./events.js'), + friction: require('./friction.js'), + gravity: require('./gravity.js'), + gyro: require('./gyro.js'), + manipulation: require('./manipulation.js'), + mixed: require('./mixed.js'), + newtonsCradle: require('./newtonsCradle.js'), + ragdoll: require('./ragdoll.js'), + pyramid: require('./pyramid.js'), + raycasting: require('./raycasting.js'), + restitution: require('./restitution.js'), + rounded: require('./rounded.js'), + sensors: require('./sensors.js'), + sleeping: require('./sleeping.js'), + slingshot: require('./slingshot.js'), + softBody: require('./softBody.js'), + sprites: require('./sprites.js'), + stack: require('./stack.js'), + staticFriction: require('./staticFriction.js'), + stress: require('./stress.js'), + stress2: require('./stress2.js'), + svg: require('./svg.js'), + terrain: require('./terrain.js'), + timescale: require('./timescale.js'), + views: require('./views.js'), + wreckingBall: require('./wreckingBall.js') +}; \ No newline at end of file diff --git a/examples/manipulation.js b/examples/manipulation.js index 0285887..ff56ee6 100644 --- a/examples/manipulation.js +++ b/examples/manipulation.js @@ -138,4 +138,8 @@ Example.manipulation = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/mixed.js b/examples/mixed.js index e6b4f3e..d5288c5 100644 --- a/examples/mixed.js +++ b/examples/mixed.js @@ -103,4 +103,8 @@ Example.mixed = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/newtonsCradle.js b/examples/newtonsCradle.js index 1eaf398..dd24864 100644 --- a/examples/newtonsCradle.js +++ b/examples/newtonsCradle.js @@ -74,4 +74,8 @@ Example.newtonsCradle = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/pyramid.js b/examples/pyramid.js index f5209a6..ba4fc54 100644 --- a/examples/pyramid.js +++ b/examples/pyramid.js @@ -79,4 +79,8 @@ Example.pyramid = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/ragdoll.js b/examples/ragdoll.js index 5dfbfae..df12bb9 100644 --- a/examples/ragdoll.js +++ b/examples/ragdoll.js @@ -495,4 +495,8 @@ Example.ragdoll.ragdoll = function(x, y, scale, options) { }); return person; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/raycasting.js b/examples/raycasting.js index 3ecb806..6e37414 100644 --- a/examples/raycasting.js +++ b/examples/raycasting.js @@ -133,4 +133,8 @@ Example.raycasting = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/restitution.js b/examples/restitution.js index d8a7ee9..e72d56c 100644 --- a/examples/restitution.js +++ b/examples/restitution.js @@ -83,4 +83,8 @@ Example.restitution = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/rounded.js b/examples/rounded.js index 9c4b1b8..81ddc28 100644 --- a/examples/rounded.js +++ b/examples/rounded.js @@ -107,4 +107,8 @@ Example.rounded = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/sensors.js b/examples/sensors.js index 00a87e4..6b0c36f 100644 --- a/examples/sensors.js +++ b/examples/sensors.js @@ -129,4 +129,8 @@ Example.sensors = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/sleeping.js b/examples/sleeping.js index eb450c9..847875a 100644 --- a/examples/sleeping.js +++ b/examples/sleeping.js @@ -102,4 +102,8 @@ Example.sleeping = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/slingshot.js b/examples/slingshot.js index db21200..0f9b995 100644 --- a/examples/slingshot.js +++ b/examples/slingshot.js @@ -98,4 +98,8 @@ Example.slingshot = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/softBody.js b/examples/softBody.js index bc9682b..0ad3ff0 100644 --- a/examples/softBody.js +++ b/examples/softBody.js @@ -83,4 +83,8 @@ Example.softBody = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/sprites.js b/examples/sprites.js index ed26fb4..9fa0b47 100644 --- a/examples/sprites.js +++ b/examples/sprites.js @@ -111,4 +111,8 @@ Example.sprites = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/stack.js b/examples/stack.js index 8e5b09d..8d69533 100644 --- a/examples/stack.js +++ b/examples/stack.js @@ -79,4 +79,8 @@ Example.stack = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/staticFriction.js b/examples/staticFriction.js index 3040b64..4dfb13a 100644 --- a/examples/staticFriction.js +++ b/examples/staticFriction.js @@ -104,4 +104,8 @@ Example.staticFriction = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/stress.js b/examples/stress.js index 1ac5f8b..9d08c57 100644 --- a/examples/stress.js +++ b/examples/stress.js @@ -77,4 +77,8 @@ Example.stress = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/stress2.js b/examples/stress2.js index 886df32..af4f937 100644 --- a/examples/stress2.js +++ b/examples/stress2.js @@ -77,4 +77,8 @@ Example.stress2 = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/svg.js b/examples/svg.js index cae0bcd..be191a4 100644 --- a/examples/svg.js +++ b/examples/svg.js @@ -40,44 +40,46 @@ Example.svg = function() { 'iconmonstr-user-icon' ]; - for (var i = 0; i < svgs.length; i += 1) { - (function(i) { - $.get('./svg/' + svgs[i] + '.svg').done(function(data) { - var vertexSets = [], - color = Common.choose(['#556270', '#4ECDC4', '#C7F464', '#FF6B6B', '#C44D58']); + if (typeof $ !== 'undefined') { + for (var i = 0; i < svgs.length; i += 1) { + (function(i) { + $.get('./svg/' + svgs[i] + '.svg').done(function(data) { + var vertexSets = [], + color = Common.choose(['#556270', '#4ECDC4', '#C7F464', '#FF6B6B', '#C44D58']); - $(data).find('path').each(function(i, path) { - var points = Svg.pathToVertices(path, 30); - vertexSets.push(Vertices.scale(points, 0.4, 0.4)); + $(data).find('path').each(function(i, path) { + var points = Svg.pathToVertices(path, 30); + vertexSets.push(Vertices.scale(points, 0.4, 0.4)); + }); + + World.add(world, Bodies.fromVertices(100 + i * 150, 200 + i * 50, vertexSets, { + render: { + fillStyle: color, + strokeStyle: color, + lineWidth: 1 + } + }, true)); }); + })(i); + } - World.add(world, Bodies.fromVertices(100 + i * 150, 200 + i * 50, vertexSets, { - render: { - fillStyle: color, - strokeStyle: color, - lineWidth: 1 - } - }, true)); + $.get('./svg/svg.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)); }); - })(i); - } - $.get('./svg/svg.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)); + World.add(world, Bodies.fromVertices(400, 80, vertexSets, { + render: { + fillStyle: color, + strokeStyle: color, + lineWidth: 1 + } + }, true)); }); - - World.add(world, Bodies.fromVertices(400, 80, vertexSets, { - render: { - fillStyle: color, - strokeStyle: color, - lineWidth: 1 - } - }, true)); - }); + } World.add(world, [ Bodies.rectangle(400, 0, 800, 50, { isStatic: true }), @@ -120,4 +122,8 @@ Example.svg = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/terrain.js b/examples/terrain.js index 4152258..bd69413 100644 --- a/examples/terrain.js +++ b/examples/terrain.js @@ -36,36 +36,38 @@ Example.terrain = function() { // add bodies var terrain; - $.get('./svg/terrain.svg').done(function(data) { - var vertexSets = []; + if (typeof $ !== 'undefined') { + $.get('./svg/terrain.svg').done(function(data) { + var vertexSets = []; - $(data).find('path').each(function(i, path) { - vertexSets.push(Svg.pathToVertices(path, 30)); + $(data).find('path').each(function(i, path) { + vertexSets.push(Svg.pathToVertices(path, 30)); + }); + + terrain = Bodies.fromVertices(400, 350, vertexSets, { + isStatic: true, + render: { + fillStyle: '#2e2b44', + strokeStyle: '#2e2b44', + lineWidth: 1 + } + }, 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) { + if (Query.point([terrain], { x: x, y: y }).length === 0) { + return Bodies.polygon(x, y, 5, 12, bodyOptions); + } + })); }); - - terrain = Bodies.fromVertices(400, 350, vertexSets, { - isStatic: true, - render: { - fillStyle: '#2e2b44', - strokeStyle: '#2e2b44', - lineWidth: 1 - } - }, 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) { - if (Query.point([terrain], { x: x, y: y }).length === 0) { - return Bodies.polygon(x, y, 5, 12, bodyOptions); - } - })); - }); + } // add mouse control var mouse = Mouse.create(render.canvas), @@ -101,4 +103,8 @@ Example.terrain = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example; +} \ No newline at end of file diff --git a/examples/timescale.js b/examples/timescale.js index 466ec02..86509c7 100644 --- a/examples/timescale.js +++ b/examples/timescale.js @@ -149,4 +149,8 @@ Example.timescale = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/views.js b/examples/views.js index aa0f456..e4afd75 100644 --- a/examples/views.js +++ b/examples/views.js @@ -180,4 +180,8 @@ Example.views = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file diff --git a/examples/wreckingBall.js b/examples/wreckingBall.js index 107eab3..18aeefe 100644 --- a/examples/wreckingBall.js +++ b/examples/wreckingBall.js @@ -91,4 +91,8 @@ Example.wreckingBall = function() { Matter.Runner.stop(runner); } }; -}; \ No newline at end of file +}; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = Example[Object.keys(Example)[0]]; +} \ No newline at end of file