mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
rename Composites function xx and yy params, closes #1095
This commit is contained in:
parent
272049ab05
commit
6bda7e86d5
1 changed files with 31 additions and 31 deletions
|
@ -24,8 +24,8 @@ var deprecated = Common.deprecated;
|
||||||
* Create a new composite containing bodies created in the callback in a grid arrangement.
|
* Create a new composite containing bodies created in the callback in a grid arrangement.
|
||||||
* This function uses the body's bounds to prevent overlaps.
|
* This function uses the body's bounds to prevent overlaps.
|
||||||
* @method stack
|
* @method stack
|
||||||
* @param {number} xx
|
* @param {number} x Starting position in X.
|
||||||
* @param {number} yy
|
* @param {number} y Starting position in Y.
|
||||||
* @param {number} columns
|
* @param {number} columns
|
||||||
* @param {number} rows
|
* @param {number} rows
|
||||||
* @param {number} columnGap
|
* @param {number} columnGap
|
||||||
|
@ -33,10 +33,10 @@ var deprecated = Common.deprecated;
|
||||||
* @param {function} callback
|
* @param {function} callback
|
||||||
* @return {composite} A new composite containing objects created in the callback
|
* @return {composite} A new composite containing objects created in the callback
|
||||||
*/
|
*/
|
||||||
Composites.stack = function(xx, yy, columns, rows, columnGap, rowGap, callback) {
|
Composites.stack = function(x, y, columns, rows, columnGap, rowGap, callback) {
|
||||||
var stack = Composite.create({ label: 'Stack' }),
|
var stack = Composite.create({ label: 'Stack' }),
|
||||||
x = xx,
|
currentX = x,
|
||||||
y = yy,
|
currentY = y,
|
||||||
lastBody,
|
lastBody,
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ var deprecated = Common.deprecated;
|
||||||
var maxHeight = 0;
|
var maxHeight = 0;
|
||||||
|
|
||||||
for (var column = 0; column < columns; column++) {
|
for (var column = 0; column < columns; column++) {
|
||||||
var body = callback(x, y, column, row, lastBody, i);
|
var body = callback(currentX, currentY, column, row, lastBody, i);
|
||||||
|
|
||||||
if (body) {
|
if (body) {
|
||||||
var bodyHeight = body.bounds.max.y - body.bounds.min.y,
|
var bodyHeight = body.bounds.max.y - body.bounds.min.y,
|
||||||
|
@ -55,19 +55,19 @@ var deprecated = Common.deprecated;
|
||||||
|
|
||||||
Body.translate(body, { x: bodyWidth * 0.5, y: bodyHeight * 0.5 });
|
Body.translate(body, { x: bodyWidth * 0.5, y: bodyHeight * 0.5 });
|
||||||
|
|
||||||
x = body.bounds.max.x + columnGap;
|
currentX = body.bounds.max.x + columnGap;
|
||||||
|
|
||||||
Composite.addBody(stack, body);
|
Composite.addBody(stack, body);
|
||||||
|
|
||||||
lastBody = body;
|
lastBody = body;
|
||||||
i += 1;
|
i += 1;
|
||||||
} else {
|
} else {
|
||||||
x += columnGap;
|
currentX += columnGap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
y += maxHeight + rowGap;
|
currentY += maxHeight + rowGap;
|
||||||
x = xx;
|
currentX = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -165,8 +165,8 @@ var deprecated = Common.deprecated;
|
||||||
* Create a new composite containing bodies created in the callback in a pyramid arrangement.
|
* Create a new composite containing bodies created in the callback in a pyramid arrangement.
|
||||||
* This function uses the body's bounds to prevent overlaps.
|
* This function uses the body's bounds to prevent overlaps.
|
||||||
* @method pyramid
|
* @method pyramid
|
||||||
* @param {number} xx
|
* @param {number} x Starting position in X.
|
||||||
* @param {number} yy
|
* @param {number} y Starting position in Y.
|
||||||
* @param {number} columns
|
* @param {number} columns
|
||||||
* @param {number} rows
|
* @param {number} rows
|
||||||
* @param {number} columnGap
|
* @param {number} columnGap
|
||||||
|
@ -174,8 +174,8 @@ var deprecated = Common.deprecated;
|
||||||
* @param {function} callback
|
* @param {function} callback
|
||||||
* @return {composite} A new composite containing objects created in the callback
|
* @return {composite} A new composite containing objects created in the callback
|
||||||
*/
|
*/
|
||||||
Composites.pyramid = function(xx, yy, columns, rows, columnGap, rowGap, callback) {
|
Composites.pyramid = function(x, y, columns, rows, columnGap, rowGap, callback) {
|
||||||
return Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y, column, row, lastBody, i) {
|
return Composites.stack(x, y, columns, rows, columnGap, rowGap, function(stackX, stackY, column, row, lastBody, i) {
|
||||||
var actualRows = Math.min(rows, Math.ceil(columns / 2)),
|
var actualRows = Math.min(rows, Math.ceil(columns / 2)),
|
||||||
lastBodyWidth = lastBody ? lastBody.bounds.max.x - lastBody.bounds.min.x : 0;
|
lastBodyWidth = lastBody ? lastBody.bounds.max.x - lastBody.bounds.min.x : 0;
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ var deprecated = Common.deprecated;
|
||||||
|
|
||||||
var xOffset = lastBody ? column * lastBodyWidth : 0;
|
var xOffset = lastBody ? column * lastBodyWidth : 0;
|
||||||
|
|
||||||
return callback(xx + xOffset + column * columnGap, y, column, row, lastBody, i);
|
return callback(x + xOffset + column * columnGap, stackY, column, row, lastBody, i);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -206,21 +206,21 @@ var deprecated = Common.deprecated;
|
||||||
* This has now moved to the [newtonsCradle example](https://github.com/liabru/matter-js/blob/master/examples/newtonsCradle.js), follow that instead as this function is deprecated here.
|
* This has now moved to the [newtonsCradle example](https://github.com/liabru/matter-js/blob/master/examples/newtonsCradle.js), follow that instead as this function is deprecated here.
|
||||||
* @deprecated moved to newtonsCradle example
|
* @deprecated moved to newtonsCradle example
|
||||||
* @method newtonsCradle
|
* @method newtonsCradle
|
||||||
* @param {number} xx
|
* @param {number} x Starting position in X.
|
||||||
* @param {number} yy
|
* @param {number} y Starting position in Y.
|
||||||
* @param {number} number
|
* @param {number} number
|
||||||
* @param {number} size
|
* @param {number} size
|
||||||
* @param {number} length
|
* @param {number} length
|
||||||
* @return {composite} A new composite newtonsCradle body
|
* @return {composite} A new composite newtonsCradle body
|
||||||
*/
|
*/
|
||||||
Composites.newtonsCradle = function(xx, yy, number, size, length) {
|
Composites.newtonsCradle = function(x, y, number, size, length) {
|
||||||
var newtonsCradle = Composite.create({ label: 'Newtons Cradle' });
|
var newtonsCradle = Composite.create({ label: 'Newtons Cradle' });
|
||||||
|
|
||||||
for (var i = 0; i < number; i++) {
|
for (var i = 0; i < number; i++) {
|
||||||
var separation = 1.9,
|
var separation = 1.9,
|
||||||
circle = Bodies.circle(xx + i * (size * separation), yy + length, size,
|
circle = Bodies.circle(x + i * (size * separation), y + length, size,
|
||||||
{ inertia: Infinity, restitution: 1, friction: 0, frictionAir: 0.0001, slop: 1 }),
|
{ inertia: Infinity, restitution: 1, friction: 0, frictionAir: 0.0001, slop: 1 }),
|
||||||
constraint = Constraint.create({ pointA: { x: xx + i * (size * separation), y: yy }, bodyB: circle });
|
constraint = Constraint.create({ pointA: { x: x + i * (size * separation), y: y }, bodyB: circle });
|
||||||
|
|
||||||
Composite.addBody(newtonsCradle, circle);
|
Composite.addBody(newtonsCradle, circle);
|
||||||
Composite.addConstraint(newtonsCradle, constraint);
|
Composite.addConstraint(newtonsCradle, constraint);
|
||||||
|
@ -235,14 +235,14 @@ var deprecated = Common.deprecated;
|
||||||
* This has now moved to the [car example](https://github.com/liabru/matter-js/blob/master/examples/car.js), follow that instead as this function is deprecated here.
|
* This has now moved to the [car example](https://github.com/liabru/matter-js/blob/master/examples/car.js), follow that instead as this function is deprecated here.
|
||||||
* @deprecated moved to car example
|
* @deprecated moved to car example
|
||||||
* @method car
|
* @method car
|
||||||
* @param {number} xx
|
* @param {number} x Starting position in X.
|
||||||
* @param {number} yy
|
* @param {number} y Starting position in Y.
|
||||||
* @param {number} width
|
* @param {number} width
|
||||||
* @param {number} height
|
* @param {number} height
|
||||||
* @param {number} wheelSize
|
* @param {number} wheelSize
|
||||||
* @return {composite} A new composite car body
|
* @return {composite} A new composite car body
|
||||||
*/
|
*/
|
||||||
Composites.car = function(xx, yy, width, height, wheelSize) {
|
Composites.car = function(x, y, width, height, wheelSize) {
|
||||||
var group = Body.nextGroup(true),
|
var group = Body.nextGroup(true),
|
||||||
wheelBase = 20,
|
wheelBase = 20,
|
||||||
wheelAOffset = -width * 0.5 + wheelBase,
|
wheelAOffset = -width * 0.5 + wheelBase,
|
||||||
|
@ -250,7 +250,7 @@ var deprecated = Common.deprecated;
|
||||||
wheelYOffset = 0;
|
wheelYOffset = 0;
|
||||||
|
|
||||||
var car = Composite.create({ label: 'Car' }),
|
var car = Composite.create({ label: 'Car' }),
|
||||||
body = Bodies.rectangle(xx, yy, width, height, {
|
body = Bodies.rectangle(x, y, width, height, {
|
||||||
collisionFilter: {
|
collisionFilter: {
|
||||||
group: group
|
group: group
|
||||||
},
|
},
|
||||||
|
@ -260,14 +260,14 @@ var deprecated = Common.deprecated;
|
||||||
density: 0.0002
|
density: 0.0002
|
||||||
});
|
});
|
||||||
|
|
||||||
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
|
var wheelA = Bodies.circle(x + wheelAOffset, y + wheelYOffset, wheelSize, {
|
||||||
collisionFilter: {
|
collisionFilter: {
|
||||||
group: group
|
group: group
|
||||||
},
|
},
|
||||||
friction: 0.8
|
friction: 0.8
|
||||||
});
|
});
|
||||||
|
|
||||||
var wheelB = Bodies.circle(xx + wheelBOffset, yy + wheelYOffset, wheelSize, {
|
var wheelB = Bodies.circle(x + wheelBOffset, y + wheelYOffset, wheelSize, {
|
||||||
collisionFilter: {
|
collisionFilter: {
|
||||||
group: group
|
group: group
|
||||||
},
|
},
|
||||||
|
@ -306,8 +306,8 @@ var deprecated = Common.deprecated;
|
||||||
* and the [cloth example](https://github.com/liabru/matter-js/blob/master/examples/cloth.js), follow those instead as this function is deprecated here.
|
* and the [cloth example](https://github.com/liabru/matter-js/blob/master/examples/cloth.js), follow those instead as this function is deprecated here.
|
||||||
* @deprecated moved to softBody and cloth examples
|
* @deprecated moved to softBody and cloth examples
|
||||||
* @method softBody
|
* @method softBody
|
||||||
* @param {number} xx
|
* @param {number} x Starting position in X.
|
||||||
* @param {number} yy
|
* @param {number} y Starting position in Y.
|
||||||
* @param {number} columns
|
* @param {number} columns
|
||||||
* @param {number} rows
|
* @param {number} rows
|
||||||
* @param {number} columnGap
|
* @param {number} columnGap
|
||||||
|
@ -318,12 +318,12 @@ var deprecated = Common.deprecated;
|
||||||
* @param {} constraintOptions
|
* @param {} constraintOptions
|
||||||
* @return {composite} A new composite softBody
|
* @return {composite} A new composite softBody
|
||||||
*/
|
*/
|
||||||
Composites.softBody = function(xx, yy, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) {
|
Composites.softBody = function(x, y, columns, rows, columnGap, rowGap, crossBrace, particleRadius, particleOptions, constraintOptions) {
|
||||||
particleOptions = Common.extend({ inertia: Infinity }, particleOptions);
|
particleOptions = Common.extend({ inertia: Infinity }, particleOptions);
|
||||||
constraintOptions = Common.extend({ stiffness: 0.2, render: { type: 'line', anchors: false } }, constraintOptions);
|
constraintOptions = Common.extend({ stiffness: 0.2, render: { type: 'line', anchors: false } }, constraintOptions);
|
||||||
|
|
||||||
var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y) {
|
var softBody = Composites.stack(x, y, columns, rows, columnGap, rowGap, function(stackX, stackY) {
|
||||||
return Bodies.circle(x, y, particleRadius, particleOptions);
|
return Bodies.circle(stackX, stackY, particleRadius, particleOptions);
|
||||||
});
|
});
|
||||||
|
|
||||||
Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);
|
Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);
|
||||||
|
|
Loading…
Reference in a new issue