Made some improvements.

This commit is contained in:
The Wobbler 2023-12-29 20:00:39 +01:00
parent 65265c6b02
commit 72f4674ee1

View file

@ -6,16 +6,15 @@ import os, sys, termios, tty, time, random
from math import sin, cos, tan, sqrt from math import sin, cos, tan, sqrt
from time import sleep 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 x = 0
y = x**2 y = x**2
# in scala the resulting coordinates will be returned # in scala the resulting coordinates will be returned
scala = [] scala = []
erde = 9.81
mond = 1.6
jupiter = 24
gravitation = erde
startwinkel = startwinkel * deg2rad startwinkel = startwinkel * deg2rad
# Calculate time of flight, actually not used # Calculate time of flight, actually not used
@ -31,7 +30,7 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk
) / gravitation ) / gravitation
# 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, 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. # 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)
@ -42,12 +41,11 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk
elif y <= ymin: elif y <= ymin:
scala += [x, ymin] scala += [x, ymin]
break
else: else:
scala += [x, ymax] scala += [x, ymax]
xold = x
return scala 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" 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 # set position of cursor
def curpos(x, y): def curpos(x, y):
print("\033[%d;%dH" % (ymax - y, x), end="", flush=True) print("\033[%d;%dH" % (ymax - y, x), end="", flush=True)
@ -89,14 +91,14 @@ if __name__ == "__main__":
schlafzeit = 0.05 schlafzeit = 0.05
### ###
# needed for erasing ol position # needed for erasing old position
xold = xmin xold = xmin
yold = ymin yold = ymin
x = xmin x = xmin
y = xmin y = xmin
# Call the function, which calculates the coordinates) # 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) 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):
@ -108,5 +110,7 @@ if __name__ == "__main__":
curpos(xold, yold) curpos(xold, yold)
print("☁️ ", end="") print("☁️ ", end="")
sleep(2)
sys.exit(home + cow + curon)
sys.exit(home + curon)