67 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-12-23 18:24:21 +03:30
import { World, Edge, Circle, Box, Chain, Math, Testbed } from "planck";
2016-03-23 22:59:54 -04:00
2024-12-24 15:07:16 +03:30
const world = new World({
gravity: { x: 0, y: -10 },
});
2016-03-23 22:59:54 -04:00
2023-08-20 03:24:33 -07:00
const testbed = Testbed.mount();
testbed.y = 0;
testbed.start(world);
2016-03-23 22:59:54 -04:00
2024-12-24 15:07:16 +03:30
const container = world.createBody({
type: "kinematic",
});
2024-12-24 19:58:07 +03:30
container.createFixture({
shape: new Edge({ x: 15, y: -5 }, { x: 25, y: 5 }),
});
container.createFixture({
shape: new Circle({ x: -10, y: -10 }, 3),
});
container.createFixture({
shape: new Circle({ x: 10, y: 10 }, 3),
});
container.createFixture({
shape: new Box(3, 3, { x: -10, y: 10 }),
});
container.createFixture({
shape: new Box(3, 3, { x: 10, y: -10 }),
});
2016-03-23 22:59:54 -04:00
container.createFixture(
2024-12-23 18:24:21 +03:30
new Chain(
[
{ x: -20, y: -20 },
{ x: 20, y: -20 },
{ x: 20, y: 20 },
{ x: -20, y: 20 },
],
true,
),
);
const n = 15;
2016-03-23 22:59:54 -04:00
2023-08-14 13:59:23 -07:00
for (let i = -n; i <= n; i++) {
for (let j = -n; j <= n; j++) {
2024-12-24 15:07:16 +03:30
const particle = world.createBody({
type: "dynamic",
position: { x: i * 1, y: j * 1 },
});
2024-12-24 19:58:07 +03:30
particle.createFixture({
shape: Math.random() > 0.5 ? new Circle(0.4) : new Box(0.4, 0.4),
});
particle.setMassData({
mass: 2,
2024-12-23 18:24:21 +03:30
center: { x: 0, y: 0 },
I: 0.4,
});
2024-12-23 18:24:21 +03:30
particle.applyForceToCenter({
x: Math.random(-100, 100),
y: Math.random(-100, 100),
});
}
}
2016-03-23 22:59:54 -04:00
container.setAngularVelocity(0.3);