Skip to content

Commit

Permalink
added Example.attractors
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Sep 3, 2016
1 parent 59bfa0b commit 758bbe8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ <h1>Matter.js Demo</h1>
<option value="avalanche">Avalanche</option>
<option value="softBody">Basic Soft Bodies</option>
<option value="cloth">Cloth</option>
<option value="attractors">Attractors (Plugin)</option>
<option value="events">Events</option>
<option value="collisionFiltering">Collision Filtering</option>
<option value="sensors">Sensors</option>
Expand Down
6 changes: 0 additions & 6 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@
var demo = Demo.create();
Matter.Demo._demo = demo;

Matter.use(
'matter-plugin-fake',
'matter-plugin-2',
window.MatterPlugin
);

// get container element for the canvas
demo.container = document.getElementById('canvas-container');

Expand Down
52 changes: 52 additions & 0 deletions examples/attractors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(function() {

var World = Matter.World,
Bodies = Matter.Bodies,
Body = Matter.Body,
Common = Matter.Common;

Example.attractors = function(demo) {
var engine = demo.engine,
world = engine.world;

Matter.use(
'matter-gravity',
'matter-world-wrap'
);

world.bounds = {
min: { x: 0, y: 0 },
max: { x: 800, y: 600 }
};

world.bodies = [];
world.gravity.scale = 0;

var G = 0.001;

for (var i = 0; i < 200; i += 1) {
var body = Bodies.circle(
Common.random(10, 790),
Common.random(10, 590),
Common.random(4, 10),
{
mass: Common.random(10, 20),
gravity: G,
frictionAir: 0
}
);

Body.setVelocity(body, {
x: Common.random(-2, 2),
y: Common.random(-2, 2)
});

World.add(world, body);
}

var renderOptions = demo.render.options;
renderOptions.showAngleIndicator = false;
renderOptions.showPositions = true;
};

})();

0 comments on commit 758bbe8

Please sign in to comment.