-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
61 lines (47 loc) · 1.15 KB
/
script.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
let screenSize;
let gameField;
const settings = {
liveChance: 0.2,
frameRate: 15,
backgroundColor: 30,
update: function() {
gameField.fillWithRandom(this.liveChance);
}
};
const gui = new dat.GUI();
function updateScreenSize() {
const bodyRect = document.body.getBoundingClientRect();
screenSize = {
width: bodyRect.width,
height: bodyRect.height,
};
resizeCanvas(screenSize.width, screenSize.height)
}
function generateGUISettings() {
gui.add(settings, 'liveChance', 0.1, 1).step(0.1);
gui.add(settings, 'frameRate', 1, 30)
.step(1)
.onChange((value) => frameRate(value));
gui.add(settings, 'update');
}
function setup() {
createCanvas();
updateScreenSize();
generateGUISettings();
window.addEventListener('resize', updateScreenSize);
gameField = new GameField(50);
frameRate(settings.frameRate);
}
function clearCanvas() {
noStroke();
fill(settings.backgroundColor);
rect(0, 0, screenSize.width, screenSize.height);
}
function draw() {
clearCanvas();
gameField.draw();
update();
}
function update() {
gameField.update();
}