Made some improvements.

This commit is contained in:
The Wobbler 2023-12-29 20:31:52 +01:00
parent 72f4674ee1
commit cc7685c458

View file

@ -8,7 +8,7 @@ from time import sleep
######################################################################################## ########################################################################################
def berechneflugbahn(xmin, xmax, ymin, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe=0, gravitation=9.81, xstep=1): def berechneflugbahn(xmax, ymax, steps, startwinkel, startgeschwindigkeit, xmin=0, ymin=0, starthoehe=0, gravitation=9.81, xstep=1):
x = 0 x = 0
y = x**2 y = x**2
@ -29,22 +29,31 @@ def berechneflugbahn(xmin, xmax, ymin, ymax, xsteps, startwinkel, startgeschwind
* (startgeschwindigkeit * sin(startwinkel) + sqrt(startgeschwindigkeit**2 * sin(startwinkel) ** 2 + 2 * gravitation * starthoehe)) * (startgeschwindigkeit * sin(startwinkel) + sqrt(startgeschwindigkeit**2 * sin(startwinkel) ** 2 + 2 * gravitation * starthoehe))
) / gravitation ) / gravitation
first_run = True
# cowlength is 2, if cow is an UTF8-Icon, otherwise 1 # cowlength is 2, if cow is an UTF8-Icon, otherwise 1
for x in range(xmin, xsteps - 1, xstep): for x in range(xmin, steps - 1, xstep):
# the formula, which generates the y position for the corresponding x, shamelessly ripped from some schoolbook and modified. # 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) y = (-(gravitation / (2 * startgeschwindigkeit**2 * cos(startwinkel) ** 2)) * x**2) + (tan(startwinkel) * x + starthoehe)
# Ensure, that nothing has to be drawn outside the viewport # Ensure, that nothing has to be drawn outside the viewport
if y <= ymax and y >= ymin:
if x >= xmax:
x = xmax
if y >= ymax:
y = ymax
elif y <= ymin:
y = ymin
# Stash away the coordinates into scala, which will be returned # Stash away the coordinates into scala, which will be returned
scala += [x, int((y * 100 + 50) / 100)] scala += [x, int((y * 100 + 50) / 100)]
elif y <= ymin: if y == ymin and not first_run:
scala += [x, ymin]
break break
else: first_run = False
scala += [x, ymax]
return scala return scala
@ -81,12 +90,12 @@ if __name__ == "__main__":
# X-Resolution of the display # X-Resolution of the display
xmax = termsize_xy[0] - 1 xmax = termsize_xy[0] - 1
xsteps = xmax xsteps = xmax * 2
ymax = termsize_xy[1] ymax = termsize_xy[1]
ymin = 0 ymin = 0
xmin = 0 xmin = 0
startwinkel = 34 startwinkel = 34
startgeschwindigkeit = 31 startgeschwindigkeit = 60
starthoehe = 0 starthoehe = 0
schlafzeit = 0.05 schlafzeit = 0.05
### ###
@ -98,7 +107,7 @@ if __name__ == "__main__":
y = xmin y = xmin
# Call the function, which calculates the coordinates) # Call the function, which calculates the coordinates)
ergebnis = berechneflugbahn(xmin, xmax, ymin, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe, g_erde, 2) ergebnis = berechneflugbahn(xmax, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe, gravitation=g_erde, xstep=2)
print(curoff) print(curoff)
# here we draw the cow # here we draw the cow
for count in range(xmin, len(ergebnis), 2): for count in range(xmin, len(ergebnis), 2):