mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 15:16:33 -08:00
Python: Make code testable
Avoid executing code on module level as this prevents importing the module for testing. Especially infinite loops are evil.
This commit is contained in:
@@ -11,18 +11,23 @@ def equation(x: float) -> float:
|
||||
return 30 * exp(-x * x / 100)
|
||||
|
||||
|
||||
print(" " * 32 + "3D PLOT")
|
||||
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n\n")
|
||||
def main():
|
||||
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
|
||||
max_column = 0
|
||||
y1 = 5 * floor(sqrt(900 - x1 * x1) / 5)
|
||||
y_plot = [" "] * 80
|
||||
for x in range(-300, 315, 15):
|
||||
x1 = x / 10
|
||||
max_column = 0
|
||||
y1 = 5 * floor(sqrt(900 - x1 * x1) / 5)
|
||||
y_plot = [" "] * 80
|
||||
|
||||
for y in range(y1, -(y1 + 5), -5):
|
||||
column = floor(25 + equation(sqrt(x1 * x1 + y * y)) - 0.7 * y)
|
||||
if column > max_column:
|
||||
max_column = column
|
||||
y_plot[column] = "*"
|
||||
print("".join(y_plot))
|
||||
for y in range(y1, -(y1 + 5), -5):
|
||||
column = floor(25 + equation(sqrt(x1 * x1 + y * y)) - 0.7 * y)
|
||||
if column > max_column:
|
||||
max_column = column
|
||||
y_plot[column] = "*"
|
||||
print("".join(y_plot))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user