mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
better default labels
This commit is contained in:
parent
d883671874
commit
e8f5b221f5
5 changed files with 16 additions and 6 deletions
|
@ -22,7 +22,7 @@ var Body = {};
|
||||||
var defaults = {
|
var defaults = {
|
||||||
id: Body.nextId(),
|
id: Body.nextId(),
|
||||||
type: 'body',
|
type: 'body',
|
||||||
label: null,
|
label: 'Body',
|
||||||
angle: 0,
|
angle: 0,
|
||||||
position: { x: 0, y: 0 },
|
position: { x: 0, y: 0 },
|
||||||
force: { x: 0, y: 0 },
|
force: { x: 0, y: 0 },
|
||||||
|
|
|
@ -28,7 +28,7 @@ var Composite = {};
|
||||||
bodies: [],
|
bodies: [],
|
||||||
constraints: [],
|
constraints: [],
|
||||||
composites: [],
|
composites: [],
|
||||||
label: null
|
label: 'Composite'
|
||||||
}, options);
|
}, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ var Constraint = {};
|
||||||
|
|
||||||
// option defaults
|
// option defaults
|
||||||
constraint.id = constraint.id || Constraint.nextId();
|
constraint.id = constraint.id || Constraint.nextId();
|
||||||
constraint.label = constraint.label;
|
constraint.label = constraint.label || 'Constraint';
|
||||||
constraint.type = 'constraint';
|
constraint.type = 'constraint';
|
||||||
constraint.stiffness = constraint.stiffness || 1;
|
constraint.stiffness = constraint.stiffness || 1;
|
||||||
constraint.angularStiffness = constraint.angularStiffness || 0;
|
constraint.angularStiffness = constraint.angularStiffness || 0;
|
||||||
|
|
|
@ -25,6 +25,7 @@ var Bodies = {};
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
var rectangle = {
|
var rectangle = {
|
||||||
|
label: 'Rectangle Body',
|
||||||
position: { x: x, y: y },
|
position: { x: x, y: y },
|
||||||
render: {
|
render: {
|
||||||
path: 'L 0 0 L ' + width + ' 0 L ' + width + ' ' + height + ' L 0 ' + height
|
path: 'L 0 0 L ' + width + ' 0 L ' + width + ' ' + height + ' L 0 ' + height
|
||||||
|
@ -56,6 +57,7 @@ var Bodies = {};
|
||||||
x3 = x2 + x1;
|
x3 = x2 + x1;
|
||||||
|
|
||||||
var trapezoid = {
|
var trapezoid = {
|
||||||
|
label: 'Trapezoid Body',
|
||||||
position: { x: x, y: y },
|
position: { x: x, y: y },
|
||||||
render: {
|
render: {
|
||||||
path: 'L 0 0 L ' + x1 + ' ' + (-height) + ' L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0'
|
path: 'L 0 0 L ' + x1 + ' ' + (-height) + ' L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0'
|
||||||
|
@ -77,6 +79,7 @@ var Bodies = {};
|
||||||
*/
|
*/
|
||||||
Bodies.circle = function(x, y, radius, options, maxSides) {
|
Bodies.circle = function(x, y, radius, options, maxSides) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
options.label = 'Circle Body';
|
||||||
|
|
||||||
// approximate circles with polygons until true circles implemented in SAT
|
// approximate circles with polygons until true circles implemented in SAT
|
||||||
|
|
||||||
|
@ -122,6 +125,7 @@ var Bodies = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
var polygon = {
|
var polygon = {
|
||||||
|
label: 'Polygon Body',
|
||||||
position: { x: x, y: y },
|
position: { x: x, y: y },
|
||||||
render: {
|
render: {
|
||||||
path: path
|
path: path
|
||||||
|
|
|
@ -22,7 +22,7 @@ var Composites = {};
|
||||||
* @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(xx, yy, columns, rows, columnGap, rowGap, callback) {
|
||||||
var stack = Composite.create(),
|
var stack = Composite.create({ label: 'Stack' }),
|
||||||
x = xx,
|
x = xx,
|
||||||
y = yy,
|
y = yy,
|
||||||
lastBody,
|
lastBody,
|
||||||
|
@ -92,6 +92,8 @@ var Composites = {};
|
||||||
|
|
||||||
Composite.addConstraint(composite, Constraint.create(constraint));
|
Composite.addConstraint(composite, Constraint.create(constraint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composite.label += ' Chain';
|
||||||
|
|
||||||
return composite;
|
return composite;
|
||||||
};
|
};
|
||||||
|
@ -141,6 +143,8 @@ var Composites = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composite.label += ' Mesh';
|
||||||
|
|
||||||
return composite;
|
return composite;
|
||||||
};
|
};
|
||||||
|
@ -196,7 +200,7 @@ var Composites = {};
|
||||||
* @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(xx, yy, number, size, length) {
|
||||||
var newtonsCradle = Composite.create();
|
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,
|
||||||
|
@ -228,7 +232,7 @@ var Composites = {};
|
||||||
wheelBOffset = width * 0.5 - wheelBase,
|
wheelBOffset = width * 0.5 - wheelBase,
|
||||||
wheelYOffset = 0;
|
wheelYOffset = 0;
|
||||||
|
|
||||||
var car = Composite.create(),
|
var car = Composite.create({ label: 'Car' }),
|
||||||
body = Bodies.trapezoid(xx, yy, width, height, 0.3, { groupId: groupId, friction: 0.01 });
|
body = Bodies.trapezoid(xx, yy, width, height, 0.3, { groupId: groupId, friction: 0.01 });
|
||||||
|
|
||||||
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
|
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
|
||||||
|
@ -293,6 +297,8 @@ var Composites = {};
|
||||||
|
|
||||||
Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);
|
Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);
|
||||||
|
|
||||||
|
softBody.label = 'Soft Body';
|
||||||
|
|
||||||
return softBody;
|
return softBody;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue