-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.js
50 lines (43 loc) · 1.5 KB
/
helpers.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
class Helpers {
constructor(engine, canvas) {};
// math
static randInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min+1)) + min;
}
static randNum(min, max) {
return Math.random() * (max - min) + min;
}
static scrambleArray(array) {
for (var i = 0; i < array.length; i++) {
var other = this.randInt(i, array.length-1);
var otherval = array[other];
array[other] = array[i];
array[i] = otherval;
}
}
// direct drawing -- seperate from the framebuffer
static drawBg(ctx) {
ctx.fillStyle = '#eeeeee';
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
static drawText(ctx, lines) {
const textsize = 20;
ctx.font = textsize + 'px arial';
ctx.textAlign = 'center';
ctx.fillStyle = '#333333';
for (var i = 0; i < lines.length; i++) {
ctx.fillText(lines[i], canvas.width/2, canvas.height/2 - lines.length*textsize/2 + i*textsize);
}
}
static drawLoadingBar(ctx, range, w=80) {
const width = w;
const height = 14;
const offset = 15;
ctx.fillStyle = '#00ff00';
ctx.strokeStyle = '#333333';
ctx.fillRect(canvas.width/2 - width/2, canvas.height/2 - height/2 + offset, width * range, height);
ctx.strokeRect(canvas.width/2 - width/2 - 0.5, canvas.height/2 - height/2 + offset - 0.5, width, height);
}
}