mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-24 13:29:01 -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.
|
||||
* This function uses the body's bounds to prevent overlaps.
|
||||
* @method stack
|
||||
* @param {number} xx
|
||||
* @param {number} yy
|
||||
* @param {number} x Starting position in X.
|
||||
* @param {number} y Starting position in Y.
|
||||
* @param {number} columns
|
||||
* @param {number} rows
|
||||
* @param {number} columnGap
|
||||
|
@ -33,10 +33,10 @@ var deprecated = Common.deprecated;
|
|||
* @param {function} 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' }),
|
||||
x = xx,
|
||||
y = yy,
|
||||
currentX = x,
|
||||
currentY = y,
|
||||
lastBody,
|
||||
i = 0;
|
||||
|
||||
|
@ -44,7 +44,7 @@ var deprecated = Common.deprecated;
|
|||
var maxHeight = 0;
|
||||
|
||||
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) {
|
||||
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 });
|
||||
|
||||
x = body.bounds.max.x + columnGap;
|
||||
currentX = body.bounds.max.x + columnGap;
|
||||
|
||||
Composite.addBody(stack, body);
|
||||
|
||||
lastBody = body;
|
||||
i += 1;
|
||||
} else {
|
||||
x += columnGap;
|
||||
currentX += columnGap;
|
||||
}
|
||||
}
|
||||
|
||||
y += maxHeight + rowGap;
|
||||
x = xx;
|
||||
currentY += maxHeight + rowGap;
|
||||
currentX = x;
|
||||
}
|
||||
|
||||
return stack;
|
||||
|
@ -165,8 +165,8 @@ var deprecated = Common.deprecated;
|
|||
* Create a new composite containing bodies created in the callback in a pyramid arrangement.
|
||||
* This function uses the body's bounds to prevent overlaps.
|
||||
* @method pyramid
|
||||
* @param {number} xx
|
||||
* @param {number} yy
|
||||
* @param {number} x Starting position in X.
|
||||
* @param {number} y Starting position in Y.
|
||||
* @param {number} columns
|
||||
* @param {number} rows
|
||||
* @param {number} columnGap
|
||||
|
@ -174,8 +174,8 @@ var deprecated = Common.deprecated;
|
|||
* @param {function} callback
|
||||
* @return {composite} A new composite containing objects created in the callback
|
||||
*/
|
||||
Composites.pyramid = function(xx, yy, columns, rows, columnGap, rowGap, callback) {
|
||||
return Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y, column, row, lastBody, i) {
|
||||
Composites.pyramid = function(x, y, columns, rows, columnGap, rowGap, callback) {
|
||||
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)),
|
||||
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;
|
||||
|
||||
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.
|
||||
* @deprecated moved to newtonsCradle example
|
||||
* @method newtonsCradle
|
||||
* @param {number} xx
|
||||
* @param {number} yy
|
||||
* @param {number} x Starting position in X.
|
||||
* @param {number} y Starting position in Y.
|
||||
* @param {number} number
|
||||
* @param {number} size
|
||||
* @param {number} length
|
||||
* @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' });
|
||||
|
||||
for (var i = 0; i < number; i++) {
|
||||
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 }),
|
||||
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.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.
|
||||
* @deprecated moved to car example
|
||||
* @method car
|
||||
* @param {number} xx
|
||||
* @param {number} yy
|
||||
* @param {number} x Starting position in X.
|
||||
* @param {number} y Starting position in Y.
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
* @param {number} wheelSize
|
||||
* @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),
|
||||
wheelBase = 20,
|
||||
wheelAOffset = -width * 0.5 + wheelBase,
|
||||
|
@ -250,7 +250,7 @@ var deprecated = Common.deprecated;
|
|||
wheelYOffset = 0;
|
||||
|
||||
var car = Composite.create({ label: 'Car' }),
|
||||
body = Bodies.rectangle(xx, yy, width, height, {
|
||||
body = Bodies.rectangle(x, y, width, height, {
|
||||
collisionFilter: {
|
||||
group: group
|
||||
},
|
||||
|
@ -260,14 +260,14 @@ var deprecated = Common.deprecated;
|
|||
density: 0.0002
|
||||
});
|
||||
|
||||
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
|
||||
var wheelA = Bodies.circle(x + wheelAOffset, y + wheelYOffset, wheelSize, {
|
||||
collisionFilter: {
|
||||
group: group
|
||||
},
|
||||
friction: 0.8
|
||||
});
|
||||
|
||||
var wheelB = Bodies.circle(xx + wheelBOffset, yy + wheelYOffset, wheelSize, {
|
||||
var wheelB = Bodies.circle(x + wheelBOffset, y + wheelYOffset, wheelSize, {
|
||||
collisionFilter: {
|
||||
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.
|
||||
* @deprecated moved to softBody and cloth examples
|
||||
* @method softBody
|
||||
* @param {number} xx
|
||||
* @param {number} yy
|
||||
* @param {number} x Starting position in X.
|
||||
* @param {number} y Starting position in Y.
|
||||
* @param {number} columns
|
||||
* @param {number} rows
|
||||
* @param {number} columnGap
|
||||
|
@ -318,12 +318,12 @@ var deprecated = Common.deprecated;
|
|||
* @param {} constraintOptions
|
||||
* @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);
|
||||
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) {
|
||||
return Bodies.circle(x, y, particleRadius, particleOptions);
|
||||
var softBody = Composites.stack(x, y, columns, rows, columnGap, rowGap, function(stackX, stackY) {
|
||||
return Bodies.circle(stackX, stackY, particleRadius, particleOptions);
|
||||
});
|
||||
|
||||
Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);
|
||||
|
|
Loading…
Reference in a new issue