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 = {
|
||||
id: Body.nextId(),
|
||||
type: 'body',
|
||||
label: null,
|
||||
label: 'Body',
|
||||
angle: 0,
|
||||
position: { x: 0, y: 0 },
|
||||
force: { x: 0, y: 0 },
|
||||
|
|
|
@ -28,7 +28,7 @@ var Composite = {};
|
|||
bodies: [],
|
||||
constraints: [],
|
||||
composites: [],
|
||||
label: null
|
||||
label: 'Composite'
|
||||
}, options);
|
||||
};
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ var Constraint = {};
|
|||
|
||||
// option defaults
|
||||
constraint.id = constraint.id || Constraint.nextId();
|
||||
constraint.label = constraint.label;
|
||||
constraint.label = constraint.label || 'Constraint';
|
||||
constraint.type = 'constraint';
|
||||
constraint.stiffness = constraint.stiffness || 1;
|
||||
constraint.angularStiffness = constraint.angularStiffness || 0;
|
||||
|
|
|
@ -25,6 +25,7 @@ var Bodies = {};
|
|||
options = options || {};
|
||||
|
||||
var rectangle = {
|
||||
label: 'Rectangle Body',
|
||||
position: { x: x, y: y },
|
||||
render: {
|
||||
path: 'L 0 0 L ' + width + ' 0 L ' + width + ' ' + height + ' L 0 ' + height
|
||||
|
@ -56,6 +57,7 @@ var Bodies = {};
|
|||
x3 = x2 + x1;
|
||||
|
||||
var trapezoid = {
|
||||
label: 'Trapezoid Body',
|
||||
position: { x: x, y: y },
|
||||
render: {
|
||||
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) {
|
||||
options = options || {};
|
||||
options.label = 'Circle Body';
|
||||
|
||||
// approximate circles with polygons until true circles implemented in SAT
|
||||
|
||||
|
@ -122,6 +125,7 @@ var Bodies = {};
|
|||
}
|
||||
|
||||
var polygon = {
|
||||
label: 'Polygon Body',
|
||||
position: { x: x, y: y },
|
||||
render: {
|
||||
path: path
|
||||
|
|
|
@ -22,7 +22,7 @@ var Composites = {};
|
|||
* @return {composite} A new composite containing objects created in the callback
|
||||
*/
|
||||
Composites.stack = function(xx, yy, columns, rows, columnGap, rowGap, callback) {
|
||||
var stack = Composite.create(),
|
||||
var stack = Composite.create({ label: 'Stack' }),
|
||||
x = xx,
|
||||
y = yy,
|
||||
lastBody,
|
||||
|
@ -92,6 +92,8 @@ var Composites = {};
|
|||
|
||||
Composite.addConstraint(composite, Constraint.create(constraint));
|
||||
}
|
||||
|
||||
composite.label += ' Chain';
|
||||
|
||||
return composite;
|
||||
};
|
||||
|
@ -141,6 +143,8 @@ var Composites = {};
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
composite.label += ' Mesh';
|
||||
|
||||
return composite;
|
||||
};
|
||||
|
@ -196,7 +200,7 @@ var Composites = {};
|
|||
* @return {composite} A new composite newtonsCradle body
|
||||
*/
|
||||
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++) {
|
||||
var separation = 1.9,
|
||||
|
@ -228,7 +232,7 @@ var Composites = {};
|
|||
wheelBOffset = width * 0.5 - wheelBase,
|
||||
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 });
|
||||
|
||||
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
|
||||
|
@ -293,6 +297,8 @@ var Composites = {};
|
|||
|
||||
Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions);
|
||||
|
||||
softBody.label = 'Soft Body';
|
||||
|
||||
return softBody;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue