36 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2017-03-18 18:37:00 -04:00
planck.testbed('Mixer', function(testbed) {
var pl = planck, Vec2 = pl.Vec2;
2021-01-25 22:41:21 -08:00
var world = new pl.World(Vec2(0, -10));
2016-03-23 22:59:54 -04:00
2017-01-23 00:18:22 -05:00
testbed.y = 0;
2016-03-23 22:59:54 -04:00
2018-10-20 23:34:22 -07:00
var container = world.createKinematicBody();
container.createFixture(pl.Edge(Vec2(15, -5), Vec2(25, 5)));
2021-01-25 22:41:21 -08:00
container.createFixture(pl.Circle(Vec2(-10, -10), 3));
container.createFixture(pl.Circle(Vec2(10, 10), 3));
container.createFixture(pl.Box(3, 3, Vec2(-10, 10)));
container.createFixture(pl.Box(3, 3, Vec2(10, -10)));
2016-03-23 22:59:54 -04:00
2021-01-25 22:41:21 -08:00
container.createFixture(pl.Chain(
[Vec2(-20, -20), Vec2(20, -20), Vec2(20, 20), Vec2(-20, 20)],
true
));
2016-03-23 22:59:54 -04:00
for (var i = -5; i <= 5; i++) {
for (var j = -5; j <= 5; j++) {
2018-10-20 23:34:22 -07:00
var particle = world.createDynamicBody(Vec2(i * 2, j * 2));
2021-01-25 22:41:21 -08:00
particle.createFixture(Math.random() > 0.5 ? pl.Circle(0.6) : pl.Box(0.6, 0.4));
2018-10-20 23:34:22 -07:00
particle.setMassData({
2016-03-23 22:59:54 -04:00
mass : 2,
center : Vec2(),
I : 0.4
2018-10-20 23:34:22 -07:00
});
particle.applyForceToCenter(Vec2(pl.Math.random(-100, 100), pl.Math.random(-100, 100)));
2016-03-23 22:59:54 -04:00
}
}
2018-10-20 23:34:22 -07:00
container.setAngularVelocity(0.3);
2016-03-23 22:59:54 -04:00
return world
2021-01-25 22:41:21 -08:00
});