mirror of
https://github.com/He4eT/BrailleGameOfLife.git
synced 2026-05-05 00:47:29 +00:00
Index: demo
This commit is contained in:
parent
8fafb5a8d5
commit
06eb121fb0
1 changed files with 40 additions and 0 deletions
40
index.js
Normal file
40
index.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
const {
|
||||
lifeStep
|
||||
} = require('./src/life')
|
||||
|
||||
const {
|
||||
gridToArrs,
|
||||
arrToPattern,
|
||||
patternToBraille
|
||||
} = require('./src/braille')
|
||||
|
||||
/* */
|
||||
|
||||
const rnd = _ =>
|
||||
(2 * Math.random()) | 0
|
||||
|
||||
const randomGrid = (h, w) =>
|
||||
Array(h).fill().map(_ =>
|
||||
Array(w).fill().map(_ =>
|
||||
rnd()))
|
||||
|
||||
/* */
|
||||
|
||||
process.stdout.write('\x1Bc')
|
||||
|
||||
const { rows, columns } = process.stdout
|
||||
let grid = lifeStep(
|
||||
randomGrid(rows * 4, columns * 2))
|
||||
|
||||
setInterval(_ => {
|
||||
const img = []
|
||||
.concat(...gridToArrs(grid))
|
||||
.map(arrToPattern)
|
||||
.map(patternToBraille)
|
||||
.join``
|
||||
|
||||
process.stdout.cursorTo(0, 0)
|
||||
process.stdout.write(img)
|
||||
|
||||
grid = lifeStep(grid)
|
||||
}, 500)
|
||||
Loading…
Add table
Add a link
Reference in a new issue