Skip to content

Commit

Permalink
added module export to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Sep 14, 2019
1 parent 6b698ea commit f9ea799
Show file tree
Hide file tree
Showing 44 changed files with 349 additions and 124 deletions.
6 changes: 5 additions & 1 deletion examples/airFriction.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ Example.airFriction = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/avalanche.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ Example.avalanche = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/ballPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ Example.ballPool = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,8 @@ Example.bridge = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/broadphase.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ Example.broadphase = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ Example.car = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/catapult.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ Example.catapult = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@ Example.chains = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/circleStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@ Example.circleStack = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/cloth.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ Example.cloth = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/collisionFiltering.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,8 @@ Example.collisionFiltering = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/compositeManipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ Example.compositeManipulation = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/compound.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ Example.compound = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/compoundStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ Example.compoundStack = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/concave.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ Example.concave = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/constraints.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,8 @@ Example.constraints = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/doublePendulum.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,8 @@ Example.doublePendulum = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,8 @@ Example.events = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/friction.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ Example.friction = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/gravity.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ Example.gravity = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
50 changes: 29 additions & 21 deletions examples/gyro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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 (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;
}
};

window.addEventListener('deviceorientation', updateGravity);
window.addEventListener('deviceorientation', updateGravity);
}

// add mouse control
var mouse = Mouse.create(render.canvas),
Expand Down Expand Up @@ -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);
}
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
45 changes: 45 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -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')
};
6 changes: 5 additions & 1 deletion examples/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,8 @@ Example.manipulation = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ Example.mixed = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
6 changes: 5 additions & 1 deletion examples/newtonsCradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ Example.newtonsCradle = function() {
Matter.Runner.stop(runner);
}
};
};
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = Example[Object.keys(Example)[0]];
}
Loading

0 comments on commit f9ea799

Please sign in to comment.