Created
October 30, 2018 00:34
-
-
Save AtoraSuunva/79ae980ab34d9833bb9ee63a7ec7681f to your computer and use it in GitHub Desktop.
choo choo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const train = [ | |
` ooo | |
o ____ | |
_||__| | ______ ______ ______ | |
( | | | | | | | | |
/-()---() ~ ()--() ~ ()--() ~ ()--()`, | |
` | |
oo | |
o ____ | |
_||__| | ______ ______ ______ | |
( | | | | | | | | |
/-()---() ~ ()--() ~ ()--() ~ ()--()`, | |
` ooo | |
oo | |
____ | |
_||__| | ______ ______ ______ | |
( | | | | | | | | |
/-()---() ~ ()--() ~ ()--() ~ ()--()` | |
].map(v=>v.split('\n')) | |
const longestFrame = longestIn(train) | |
let col = process.stdout.columns, | |
x = col, | |
t = 100 | |
console.log('\033[2J') //clear the screen | |
;(async () => { | |
while (x > -longestFrame) { | |
for (let f of train) { | |
for (let i = 0; i < f.length; i++) { | |
process.stdout.cursorTo((x < 0) ? 0 : x, i) | |
process.stdout.write(f[i].substring((x < 0) ? -x : 0, (x > col - longestFrame) ? col - x : undefined) + ' ') | |
} | |
x-- | |
await timeout(t) | |
} | |
} | |
})() | |
/////////// | |
// stuff // | |
/////////// | |
function longestIn(a) { | |
let b = 0 | |
for (c of a) { | |
for (d of c) { | |
if (d.length > b) b = d.length | |
} | |
} | |
return b | |
} | |
function timeout(ms) {return new Promise(a => setTimeout(a, ms))} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment