-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathfastLoop.js
52 lines (46 loc) · 951 Bytes
/
fastLoop.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
// @ts-check
kaplay();
loadBean();
const interval = 0.001;
const delay = 1;
loop(
interval,
() => {
const bean = add([
sprite("bean"),
pos(rand(vec2(0), vec2(width(), height()))),
]);
wait(delay, () => {
destroy(bean);
});
},
-1,
true,
);
const counter = add([
pos(10, 10),
text(""),
z(9999),
]);
add([
pos(counter.pos),
rect(counter.width, counter.height),
color(BLACK),
z(counter.z - 1),
{
update() {
this.width = counter.width;
this.height = counter.height;
},
},
]);
var beanCount = 0;
onAdd(() => beanCount++);
onDestroy(() => beanCount--);
loop(0.1, () => {
const error = 100 * Math.abs((delay / interval) - beanCount)
/ (delay / interval);
counter.text = `${beanCount.toFixed().padStart(5)} beans\nerror: ${
error.toFixed(2).padStart(5)
}%`;
});