-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (66 loc) · 1.63 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// module aliases
let { Engine, Render, Runner, Bodies, Composite } = Matter;
// create an engine
let engine = Engine.create({
timing: {
timeScale: 0.3,
},
});
const width = window.innerWidth > 0 ? window.innerWidth : screen.width;
const height = window.innerHeight > 0 ? window.innerHeight : screen.height;
// create runner
let runner = Runner.create();
let ground = Bodies.rectangle(width / 2, height - 300, width / 2, 60, {
isStatic: true,
});
// create a renderer
let render = Render.create({
element: document.getElementById("canvas"),
engine: engine,
options: {
width: width - 18,
height: height - 150,
},
});
generateWorld();
function clearTheWorld() {
Composite.clear(engine.world);
Composite.add(engine.world, ground);
}
function kaboom() {
let manyShapes = new Array(50)
.fill()
.map(() =>
Bodies.polygon(
Math.random() * 1 + width / 2,
Math.random() * 450 + 1,
Math.random() * 16 + 1,
Math.random() * 80 + 1
)
);
// add all of the bodies to the world
Composite.add(engine.world, manyShapes);
// run the engine
Runner.run(runner, engine);
}
function addShape() {
// to be continued
// let oneShape = Bodies.circle(80, 80, 80);
let oneShape = Bodies.polygon(
// Math.random() * (width / 2) + 1,
width / 2,
0,
Math.random() * 12 + 1,
Math.random() * 150 + 100
);
Composite.add(engine.world, oneShape);
// run the engine
Runner.run(runner, engine);
}
function generateWorld() {
Composite.add(engine.world, ground);
// run the renderer
Render.run(render);
// run the engine
Runner.run(runner, engine);
}