Created
June 28, 2020 20:33
-
-
Save dirask/de97693a3a7ab82552bc8870e9d2df4e to your computer and use it in GitHub Desktop.
JavaScript and animated sinus in console example 1
This file contains hidden or 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
// π β 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