Skip to content

Commit

Permalink
improved Example.chains using pin constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed May 3, 2017
1 parent 0e15099 commit 9d2f0ff
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions examples/chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,52 @@ Example.chains = function() {
// add bodies
var group = Body.nextGroup(true);

var ropeA = Composites.stack(200, 100, 4, 2, 10, 10, function(x, y) {
var ropeA = Composites.stack(100, 50, 8, 1, 10, 10, function(x, y) {
return Bodies.rectangle(x, y, 50, 20, { collisionFilter: { group: group } });
});

Composites.chain(ropeA, 0.5, 0, -0.5, 0, { stiffness: 0.8, length: 2 });
Composite.add(ropeA, Constraint.create({
bodyB: ropeA.bodies[0],
pointB: { x: -25, y: 0 },
pointA: { x: 200, y: 100 },
pointA: { x: ropeA.bodies[0].position.x, y: ropeA.bodies[0].position.y },
stiffness: 0.5
}));

World.add(world, ropeA);

group = Body.nextGroup(true);

var ropeB = Composites.stack(500, 100, 5, 2, 10, 10, function(x, y) {
var ropeB = Composites.stack(350, 50, 10, 1, 10, 10, function(x, y) {
return Bodies.circle(x, y, 20, { collisionFilter: { group: group } });
});

Composites.chain(ropeB, 0.5, 0, -0.5, 0, { stiffness: 0.8, length: 2 });
Composite.add(ropeB, Constraint.create({
bodyB: ropeB.bodies[0],
pointB: { x: -20, y: 0 },
pointA: { x: 500, y: 100 },
pointA: { x: ropeB.bodies[0].position.x, y: ropeB.bodies[0].position.y },
stiffness: 0.5
}));

group = Body.nextGroup(true);

var ropeC = Composites.stack(600, 50, 13, 1, 10, 10, function(x, y) {
return Bodies.rectangle(x - 20, y, 50, 20, { collisionFilter: { group: group }, chamfer: 5 });
});

Composites.chain(ropeC, 0.3, 0, -0.3, 0, { stiffness: 1, length: 0 });
Composite.add(ropeC, Constraint.create({
bodyB: ropeC.bodies[0],
pointB: { x: -20, y: 0 },
pointA: { x: ropeC.bodies[0].position.x, y: ropeC.bodies[0].position.y },
stiffness: 0.5
}));

World.add(world, ropeB);
World.add(world, [
ropeA,
ropeB,
ropeC,
Bodies.rectangle(400, 600, 1200, 50.5, { isStatic: true })
]);

// add mouse control
var mouse = Mouse.create(render.canvas),
Expand Down

0 comments on commit 9d2f0ff

Please sign in to comment.