Skip to content

Instantly share code, notes, and snippets.

@cho45

cho45/sine.js

Created Dec 12, 2019
Embed
What would you like to do?
//#!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
You can’t perform that action at this time.