forked from Altanis/kinetics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
executable file
·58 lines (50 loc) · 1.55 KB
/
bench.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
const {System, Body, Polygon, Vector} = require('./build/kinetics.min');
const system = new System({
tickRate: 60,
friction: 0.1,
gravity: new Vector(0, 0),
collisionInfo: {
cellSize: 6,
},
camera: {
zoom: 1,
},
bounds: new Vector(1920, 1080),
});
function random(min, max) {
return Math.random() * (max - min) + min;
}
function calculateRadius(width, height, centerX, centerY) {
const halfWidth = width / 2;
const halfHeight = height / 2;
const diagonal = Math.sqrt(halfWidth ** 2 + halfHeight ** 2);
const radius = Math.max(diagonal, Math.abs(centerX), Math.abs(centerY));
return radius;
}
// const sysRad = calculateRadius(1920, 1080, 1920 / 2, 1080 / 2);
const sysRad = calculateRadius(1920, 1080, 1920 / 2, 1080 / 2);
for (let i = 0; i < 50_000; i++) {
const x = Math.random() * ((sysRad - 2000) * 2) - (sysRad - 2000);
const y = Math.random() * ((sysRad - 2000) * 2) - (sysRad - 2000);
const radius = random(3, 13);
const body = new Body(
new Polygon({
form: {
// vertices: [new Vector(x, y)],
sides: 5,
radius,
offset: {x, y},
},
radius,
mass: 10,
speed: 1,
rotate: false,
elasticity: 1,
angularSpeed: 1,
// sleepThreshold: 1E-6
}),
system,
);
system.addBody(body);
}
setInterval(() => console.log('wur/mem', system.performance.worldUpdateRate, ' ', system.performance.memoryUsage));