From cbd60f372d761867adf4948bc296f4deb24d9cdd Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Tue, 14 Nov 2023 16:04:03 +0100 Subject: [PATCH] mehr kleinigkeiten korrigiert --- parabeltest.py | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/parabeltest.py b/parabeltest.py index 2dd17ec..1f89ad3 100755 --- a/parabeltest.py +++ b/parabeltest.py @@ -18,6 +18,7 @@ xmax = termsize_xy[0] - 1 ymax = termsize_xy[1] ymin = 0 xmin = 0 +xold = xmin # pi is not defined by default pi = 3.1416 @@ -28,6 +29,8 @@ def curpos(x, y): print("\033[%d;%dH" % (ymax - y, x), end="", flush=True) +outputfile = open("cowyeetflugbahn.txt", "w") + # CTRL and ESC-codes for the used outputdevice. Probably a terminal. clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h" @@ -46,21 +49,23 @@ scala = [] # used, if input is disabled starthoehe = 0 -startwinkel = 26 -startgeschwindigkeit = 23 -loeschen = "n" +startwinkel = 26 * deg2rad +startgeschwindigkeit = 36 +loeschen = "y" -# Be a friendly host, lets have a talk. -# comment out to speed up testing -starthoehe = float(input("Starthöhe in Metern, empf: 0-20: ")) -startwinkel = float(input("Startwinkel 0° - 90°: ")) * deg2rad -startgeschwindigkeit = float(input("Startgeschwindigkeit Meter (zb 20) pro Sekunde: ")) -loeschen = input("Kuh löschen? (y/n)") +bla = input("Parameter editieren (y) oder Vorgabe nutzen?") +if bla == "y": + # Be a friendly host, lets have a talk. + # comment out to speed up testing + starthoehe = float(input("Starthöhe in Metern, empf: 0-20: ")) + startwinkel = float(input("Startwinkel 0° - 90°: ")) * deg2rad + startgeschwindigkeit = float(input("Startgeschwindigkeit Meter (zb 20) pro Sekunde: ")) + loeschen = input("Kuh löschen? (y/n)") #### # Calculate time of flight flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation - +schlafdauer = flugdauer / xmax # Calculate maximum height hoehe = 0.5 * gravitation * flugdauer**2 + starthoehe @@ -88,6 +93,8 @@ print( starthoehe, "\nhoehe: ", hoehe, + "\nschlafdauer: ", + schlafdauer, ) bla = input("CR please:") @@ -96,23 +103,26 @@ bla = input("CR please:") curpos(1, ymax) # cowlength is 2, if cow is an UTF8-Icon, otherwise 1 -for x in range(1, xsteps, cowlength): +for x in range(xmin, xsteps - 1, cowlength): # the formula, which generates the y position for the corresponding x, shamelessly ripped from some schoolbook and modified. yold = y y = (-(gravitation / (2 * startgeschwindigkeit**2 * cos(startwinkel) ** 2)) * x**2) + (tan(startwinkel) * x + starthoehe) + time.sleep(schlafdauer) # Ensure, that nothing has to be drawn outside the viewport if y < ymax and y > ymin: curpos(x, y) print(cow, end="") # Stash awa the coordinates into scala, which will be returned scala += [x, int(y * 10 + 5) / 10] - time.sleep(0.03) if loeschen == "y": - curpos(x - 2, yold) - print(" ", end="") + curpos(xold, yold) + print(" ", end="") + else: + scala += [x, 0] + xold = x curpos(0, 0) -# print(scala) +outputfile.write(str(scala)) sys.exit(curon + "Moooooooooooo.")