-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 799 Bytes
/
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
'use strict';
let life = require('./lib/life');
function renderLifeGame(lifeGame) {
for (let idx = 0; idx < lifeGame.board.length; idx += lifeGame.size) {
process.stdout.write(
lifeGame.board
.slice(idx, idx + lifeGame.size)
.reduceRight((acc, value) => (value ? '#' : ' ') + acc, '\n')
);
}
process.stdout.write('\x1B[' + lifeGame.size + 'A');
}
(function () {
let lifeGame = life();
lifeGame.setBoard(Array.from(new Array(40 * 40), () => 0));
// Glider gun
[
242, 243, 203, 95, 94, 133, 172, 212,
252, 293, 334, 335, 225, 226, 186, 385,
386, 426, 268, 269, 308, 309, 310, 348,
349, 356, 357, 317
].forEach(v => lifeGame.board[v] = 1);
setInterval(() => {
lifeGame.next();
renderLifeGame(lifeGame);
}, 1000 / 60);
})();