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();
|
2023-07-31 21:47:06 -07:00
|
|
|
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
|
|
|
|
2024-12-15 13:30:32 +03:30
|
|
|
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,
|
|
|
|
|
),
|
2024-12-15 13:30:32 +03:30
|
|
|
);
|
2023-07-31 21:47:06 -07:00
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
});
|
2023-07-31 21:47:06 -07:00
|
|
|
particle.setMassData({
|
2024-12-15 13:30:32 +03:30
|
|
|
mass: 2,
|
2024-12-23 18:24:21 +03:30
|
|
|
center: { x: 0, y: 0 },
|
2024-12-15 13:30:32 +03:30
|
|
|
I: 0.4,
|
2023-07-31 21:47:06 -07:00
|
|
|
});
|
2024-12-23 18:24:21 +03:30
|
|
|
particle.applyForceToCenter({
|
|
|
|
|
x: Math.random(-100, 100),
|
|
|
|
|
y: Math.random(-100, 100),
|
|
|
|
|
});
|
2023-07-31 21:47:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-23 22:59:54 -04:00
|
|
|
|
2023-07-31 21:47:06 -07:00
|
|
|
container.setAngularVelocity(0.3);
|