Skip to content

Instantly share code, notes, and snippets.

@AtoraSuunva
Created October 30, 2018 00:34
Show Gist options
  • Save AtoraSuunva/79ae980ab34d9833bb9ee63a7ec7681f to your computer and use it in GitHub Desktop.
Save AtoraSuunva/79ae980ab34d9833bb9ee63a7ec7681f to your computer and use it in GitHub Desktop.
choo choo
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