-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
45 lines (39 loc) · 1.13 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { Engine, Render, Runner, World, Bodies, MouseConstraint, Mouse } = Matter;
const width = 800;
const height = 600;
const engine = Engine.create();
const { world } = engine;
const render = Render.create({
element: document.body, engine: engine, options: {
wireframes: false,
width, height
}
});
Render.run(render);
Runner.run(Runner.create(), engine);
World.add(
world,
MouseConstraint.create(engine, {
mouse: Mouse.create(render.canvas)
})
);
// Wall
const walls = [
Bodies.rectangle(400, 0, 800, 40, { isStatic: true }),
Bodies.rectangle(400, 600, 800, 40, { isStatic: true }),
Bodies.rectangle(0, 300, 40, 600, { isStatic: true }),
Bodies.rectangle(800, 300, 40, 600, { isStatic: true })
];
World.add(world, walls);
// Random Shapes
for (let i = 0;i < 50;i++) {
if (Math.random() > 0.5) {
World.add(world, Bodies.rectangle(Math.random() * width, Math.random() * height, 50, 50));
} else {
World.add(world, Bodies.circle(Math.random() * width, Math.random() * height, 35, {
render: {
fillStyle: 'red'
}
}));
}
}