Files
basic-computer-games/87_3-D_Plot/javascript/3dplot.js
Chris Reuter d26dbf036a Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment.
This change fixes that.
2021-11-21 18:30:21 -05:00

41 lines
765 B
JavaScript

// 3D PLOT
//
// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
//
function print(str)
{
document.getElementById("output").appendChild(document.createTextNode(str));
}
function tab(space)
{
var str = "";
while (space-- > 0)
str += " ";
return str;
}
function equation(input)
{
return 30 * Math.exp(-input * input / 100);
}
print(tab(32) + "3D PLOT\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
for (x = -30; x <= 30; x += 1.5) {
l = 0;
y1 = 5 * Math.floor(Math.sqrt(900 - x * x) / 5);
str = "";
for (y = y1; y >= -y1; y -= 5) {
z = Math.floor(25 + equation(Math.sqrt(x * x + y * y)) - .7 * y);
if (z > l) {
l = z;
while (str.length < z)
str += " ";
str += "*";
}
}
print(str + "\n");
}