mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-09 03:43:01 -08:00
MAINT: Apply pre-commit
Remove byte-order-marker pre-commit check as there would be many adjustments necessary
This commit is contained in:
@@ -8,90 +8,90 @@ import java.lang.Math;
|
||||
* <p>
|
||||
* Note: The idea was to create a version of the 1970's BASIC game in Java, without introducing
|
||||
* new features - no additional text, error checking, etc has been added.
|
||||
*
|
||||
*
|
||||
* Converted from BASIC to Java by Darren Cardenas.
|
||||
*/
|
||||
|
||||
// Java class names cannot begin with a letter, so class name 3dplot cannot be used
|
||||
public class Plot3D {
|
||||
|
||||
|
||||
// Java class names cannot begin with a letter, so class name 3dplot cannot be used
|
||||
public class Plot3D {
|
||||
|
||||
|
||||
public void play() {
|
||||
|
||||
showIntro();
|
||||
startGame();
|
||||
|
||||
} // End of method play
|
||||
|
||||
|
||||
private void showIntro() {
|
||||
|
||||
} // End of method play
|
||||
|
||||
|
||||
private void showIntro() {
|
||||
|
||||
System.out.println(" ".repeat(31) + "3D PLOT");
|
||||
System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
|
||||
System.out.println("\n\n\n");
|
||||
|
||||
} // End of method showIntro
|
||||
|
||||
} // End of method showIntro
|
||||
|
||||
|
||||
private void startGame() {
|
||||
private void startGame() {
|
||||
|
||||
float row = 0;
|
||||
int column = 0;
|
||||
int limit = 0;
|
||||
int plotVal = 0;
|
||||
int root = 0;
|
||||
|
||||
|
||||
String lineContent = "";
|
||||
|
||||
|
||||
// Begin loop through all rows
|
||||
for (row = -30; row <= 30; row += 1.5) {
|
||||
|
||||
limit = 0;
|
||||
|
||||
|
||||
limit = 0;
|
||||
|
||||
root = 5 * (int) Math.floor((Math.sqrt(900 - row * row) / 5));
|
||||
|
||||
|
||||
// Begin loop through all columns
|
||||
for (column = root; column >= -root; column += -5) {
|
||||
|
||||
|
||||
plotVal = 25 + (int) Math.floor(func(Math.sqrt(row * row + column * column)) - 0.7 * column);
|
||||
|
||||
|
||||
if (plotVal > limit) {
|
||||
|
||||
|
||||
limit = plotVal;
|
||||
|
||||
|
||||
// Add whitespace
|
||||
while (lineContent.length() < (plotVal-1)) {
|
||||
lineContent += " ";
|
||||
}
|
||||
}
|
||||
|
||||
lineContent += "*";
|
||||
|
||||
lineContent += "*";
|
||||
|
||||
}
|
||||
|
||||
} // End loop through all columns
|
||||
|
||||
System.out.println(lineContent);
|
||||
|
||||
|
||||
System.out.println(lineContent);
|
||||
|
||||
lineContent = "";
|
||||
|
||||
} // End loop through all rows
|
||||
|
||||
|
||||
} // End of method startGame
|
||||
|
||||
|
||||
|
||||
// Function to be plotted
|
||||
public double func(double inputVal) {
|
||||
|
||||
return (30 * Math.exp(-inputVal * inputVal / 100));
|
||||
|
||||
|
||||
return (30 * Math.exp(-inputVal * inputVal / 100));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
Plot3D plot = new Plot3D();
|
||||
plot.play();
|
||||
|
||||
|
||||
} // End of method main
|
||||
|
||||
} // End of class Plot3D
|
||||
|
||||
@@ -6,21 +6,23 @@
|
||||
|
||||
import math
|
||||
|
||||
|
||||
def equation(input):
|
||||
return 30 * math.exp(-input * input / 100)
|
||||
return 30 * math.exp(-input * input / 100)
|
||||
|
||||
|
||||
print(" " * 32 + "3D PLOT")
|
||||
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n\n")
|
||||
|
||||
for x in range (-300, 315, 15):
|
||||
x1 = x / 10
|
||||
l = 0
|
||||
y1 = 5 * math.floor(math.sqrt(900 - x1 * x1) / 5)
|
||||
yPlot = [" "] * 80
|
||||
for x in range(-300, 315, 15):
|
||||
x1 = x / 10
|
||||
l = 0
|
||||
y1 = 5 * math.floor(math.sqrt(900 - x1 * x1) / 5)
|
||||
yPlot = [" "] * 80
|
||||
|
||||
for y in range (y1, -(y1 + 5), -5):
|
||||
z = math.floor(25 + equation(math.sqrt(x1 * x1 + y * y)) - .7 * y)
|
||||
if z > l:
|
||||
l = z
|
||||
yPlot[z] = "*"
|
||||
print("".join(yPlot))
|
||||
for y in range(y1, -(y1 + 5), -5):
|
||||
z = math.floor(25 + equation(math.sqrt(x1 * x1 + y * y)) - 0.7 * y)
|
||||
if z > l:
|
||||
l = z
|
||||
yPlot[z] = "*"
|
||||
print("".join(yPlot))
|
||||
|
||||
@@ -25,4 +25,4 @@ def main
|
||||
render
|
||||
end
|
||||
|
||||
main
|
||||
main
|
||||
|
||||
Reference in New Issue
Block a user