From 758bbe831f1f4e7143e55cf711462a184cd8e797 Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 3 Sep 2016 23:27:44 +0100 Subject: [PATCH] added Example.attractors --- demo/index.html | 1 + demo/js/Demo.js | 6 ----- examples/attractors.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 examples/attractors.js diff --git a/demo/index.html b/demo/index.html index ee34922..9029700 100644 --- a/demo/index.html +++ b/demo/index.html @@ -61,6 +61,7 @@ + diff --git a/demo/js/Demo.js b/demo/js/Demo.js index c623753..9c66b11 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -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'); diff --git a/examples/attractors.js b/examples/attractors.js new file mode 100644 index 0000000..3366317 --- /dev/null +++ b/examples/attractors.js @@ -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; + }; + +})(); \ No newline at end of file