Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dirask/de97693a3a7ab82552bc8870e9d2df4e to your computer and use it in GitHub Desktop.
Save dirask/de97693a3a7ab82552bc8870e9d2df4e to your computer and use it in GitHub Desktop.
JavaScript and animated sinus in console example 1
// 👍 ✔ originally posted on:
// https://dirask.com/posts/JavaScript-and-animated-sinus-in-console-VjvxlD
// we can run this code online under above link ☘
//
function printSine(x1, x2) {
var dx = 3.14 / 4.0; // x axis step
var dy = 1.0 / 5.0; // y axis step
function printLine(character) {
var line = '';
for(var y = y1; y < y2; y += dy) {
line += '.';
}
console.log(line + character);
}
for (var rad = x1; rad < x2; rad += dx) {
var y1 = 0.0;
var y2 = Math.sin(rad) + 1;
printLine('😃');
}
}
var x1 = 0.0; // begining of sinus chart
var x2 = 6 * 3.14 // end of sinus chart
setInterval(function() {
console.clear();
printSine(x1, x2);
x1 += 0.3;
x2 += 0.3;
}, 40);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment