From 72f4674ee110873d9ceb1a75a5419415f9ae2246 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Fri, 29 Dec 2023 20:00:39 +0100 Subject: [PATCH] Made some improvements. --- physics/parabelfunc.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/physics/parabelfunc.py b/physics/parabelfunc.py index 812dc35..59b0005 100755 --- a/physics/parabelfunc.py +++ b/physics/parabelfunc.py @@ -6,16 +6,15 @@ import os, sys, termios, tty, time, random from math import sin, cos, tan, sqrt from time import sleep + ######################################################################################## -def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe): +def berechneflugbahn(xmin, xmax, ymin, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe=0, gravitation=9.81, xstep=1): x = 0 y = x**2 + # in scala the resulting coordinates will be returned scala = [] - erde = 9.81 - mond = 1.6 - jupiter = 24 - gravitation = erde + startwinkel = startwinkel * deg2rad # Calculate time of flight, actually not used @@ -31,7 +30,7 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk ) / gravitation # cowlength is 2, if cow is an UTF8-Icon, otherwise 1 - for x in range(xmin, xsteps - 1, cowlength): + for x in range(xmin, xsteps - 1, xstep): # the formula, which generates the y position for the corresponding x, shamelessly ripped from some schoolbook and modified. y = (-(gravitation / (2 * startgeschwindigkeit**2 * cos(startwinkel) ** 2)) * x**2) + (tan(startwinkel) * x + starthoehe) @@ -42,12 +41,11 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk elif y <= ymin: scala += [x, ymin] + break else: scala += [x, ymax] - xold = x - return scala @@ -58,6 +56,10 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h" +g_erde = 9.81 # gravitation examples +mond = 1.6 +jupiter = 24 + # set position of cursor def curpos(x, y): print("\033[%d;%dH" % (ymax - y, x), end="", flush=True) @@ -89,14 +91,14 @@ if __name__ == "__main__": schlafzeit = 0.05 ### - # needed for erasing ol position + # needed for erasing old position xold = xmin yold = ymin x = xmin y = xmin # Call the function, which calculates the coordinates) - ergebnis = berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe) + ergebnis = berechneflugbahn(xmin, xmax, ymin, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe, g_erde, 2) print(curoff) # here we draw the cow for count in range(xmin, len(ergebnis), 2): @@ -108,5 +110,7 @@ if __name__ == "__main__": curpos(xold, yold) print("☁️ ", end="") + sleep(2) - sys.exit(home + cow + curon) + + sys.exit(home + curon)