Skip to content

Instantly share code, notes, and snippets.

@cho45
Created December 12, 2019 02:48
Show Gist options
  • Save cho45/2d45f61fb3d36c52550ed541f76d4ec1 to your computer and use it in GitHub Desktop.
Save cho45/2d45f61fb3d36c52550ed541f76d4ec1 to your computer and use it in GitHub Desktop.
//#!node
const sleep = (n) => new Promise( (resolve) => setTimeout(resolve, n) );
const asciichart = require('asciichart')
const screen = {
clear: function () {
console.log('\x1b[2J');
},
move: function (x, y) {
console.log(`\x1b[${y};${x};H`);
}
};
async function main () {
const data = [];
for (;;) {
screen.clear();
screen.move(1, 1);
data.push(Math.sin((Date.now() / 1000) * ((Math.PI * 4) / 10)));
while (data.length > 120) data.shift();
console.log(asciichart.plot(data, {
height: 40,
}))
await sleep(100);
}
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment