forked from net-art-uchicago/10print
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10print.js
47 lines (42 loc) · 1.27 KB
/
10print.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
/*
10print algorithm which guarantees connected shapes
*/
const left_down = '╮'
const left_up = '╯'
const left_right = '─'
const right_down = '╭'
const right_up = '╰'
const down_up = '│'
const legalChars = (left, above) => {
legals = [left_down, left_up, left_right, right_down, right_up, down_up]
return legals.filter((c) => {
if (left === left_down || left === left_up || left === down_up || left === '') {
return c !== left_down && c !== left_up && c !== left_right
} else {
return c === left_down || c === left_up || c === left_right
}
}).filter((c) => {
if (above === left_up || above === left_right || above === right_up || above === '') {
return c !== left_up && c !== right_up && c !== down_up
} else {
return c === left_up || c === right_up || c === down_up
}
})
}
const w = process.stdout.columns
async function draw () {
let aboveArray = []
for (;;) {
let output = []
let prev = ''
for (let i = 0; i < w; i++) {
const legals = legalChars(prev, aboveArray.length > 0 ? aboveArray[i] : '')
prev = legals[Math.floor(Math.random() * legals.length)]
output += prev
}
console.log(output)
aboveArray = output
await new Promise(r => setTimeout(r, 1000 / 12));
}
}
draw()