mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-15 16:38:43 -05:00
deprecated Composites.newtonsCradle and added to newtonsCradle example
This commit is contained in:
parent
818f354e9c
commit
9ad980b975
2 changed files with 36 additions and 3 deletions
|
@ -31,12 +31,12 @@ Example.newtonsCradle = function() {
|
|||
var runner = Runner.create();
|
||||
Runner.run(runner, engine);
|
||||
|
||||
// add bodies
|
||||
var cradle = Composites.newtonsCradle(280, 100, 5, 30, 200);
|
||||
// see newtonsCradle function defined later in this file
|
||||
var cradle = Example.newtonsCradle.newtonsCradle(280, 100, 5, 30, 200);
|
||||
World.add(world, cradle);
|
||||
Body.translate(cradle.bodies[0], { x: -180, y: -100 });
|
||||
|
||||
cradle = Composites.newtonsCradle(280, 380, 7, 20, 140);
|
||||
cradle = Example.newtonsCradle.newtonsCradle(280, 380, 7, 20, 140);
|
||||
World.add(world, cradle);
|
||||
Body.translate(cradle.bodies[0], { x: -140, y: -100 });
|
||||
|
||||
|
@ -79,6 +79,36 @@ Example.newtonsCradle = function() {
|
|||
Example.newtonsCradle.title = 'Newton\'s Cradle';
|
||||
Example.newtonsCradle.for = '>=0.14.2';
|
||||
|
||||
/**
|
||||
* Creates a composite with a Newton's Cradle setup of bodies and constraints.
|
||||
* @method newtonsCradle
|
||||
* @param {number} xx
|
||||
* @param {number} yy
|
||||
* @param {number} number
|
||||
* @param {number} size
|
||||
* @param {number} length
|
||||
* @return {composite} A new composite newtonsCradle body
|
||||
*/
|
||||
Example.newtonsCradle.newtonsCradle = function(xx, yy, number, size, length) {
|
||||
var Composite = Matter.Composite,
|
||||
Constraint = Matter.Constraint,
|
||||
Bodies = Matter.Bodies;
|
||||
|
||||
var newtonsCradle = Composite.create({ label: 'Newtons Cradle' });
|
||||
|
||||
for (var i = 0; i < number; i++) {
|
||||
var separation = 1.9,
|
||||
circle = Bodies.circle(xx + i * (size * separation), yy + length, size,
|
||||
{ inertia: Infinity, restitution: 1, friction: 0, frictionAir: 0.0001, slop: 1 }),
|
||||
constraint = Constraint.create({ pointA: { x: xx + i * (size * separation), y: yy }, bodyB: circle });
|
||||
|
||||
Composite.addBody(newtonsCradle, circle);
|
||||
Composite.addConstraint(newtonsCradle, constraint);
|
||||
}
|
||||
|
||||
return newtonsCradle;
|
||||
};
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = Example.newtonsCradle;
|
||||
}
|
||||
|
|
|
@ -204,6 +204,7 @@ var deprecated = Common.deprecated;
|
|||
|
||||
/**
|
||||
* Creates a composite with a Newton's Cradle setup of bodies and constraints.
|
||||
* @deprecated moved to newtonsCradle example
|
||||
* @method newtonsCradle
|
||||
* @param {number} xx
|
||||
* @param {number} yy
|
||||
|
@ -228,6 +229,8 @@ var deprecated = Common.deprecated;
|
|||
return newtonsCradle;
|
||||
};
|
||||
|
||||
deprecated(Composites, 'newtonsCradle', 'Composites.newtonsCradle ➤ moved to newtonsCradle example');
|
||||
|
||||
/**
|
||||
* Creates a composite with simple car setup of bodies and constraints.
|
||||
* @deprecated moved to car example
|
||||
|
|
Loading…
Reference in a new issue