parabeltest mit korrekten parabeln & parametern

This commit is contained in:
Wolfgang Nowak 2023-11-13 19:11:51 +01:00
parent a55eabb46d
commit d4eb22f246

View file

@ -3,60 +3,103 @@
import os, sys, termios, tty, time, random import os, sys, termios, tty, time, random
from math import sin, cos, sqrt from math import sin, cos, tan, sqrt
from time import sleep from time import sleep
# Randomly choose a cow # Randomly choose a cow
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕" cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
cowlistlength = len(cows) cowlistlength = len(cows)
cow = cows[random.randint(0, cowlistlength - 1)] cow = cows[random.randint(0, cowlistlength - 1)]
# cow = "🐄" cowlength = len(cow)
# cow = "*"
cowlength=len(cow)
# Needed: find our screensize # Needed: find our screensize
termsize_xy = os.get_terminal_size() termsize_xy = os.get_terminal_size()
xmax = termsize_xy[0] - 1 xmax = termsize_xy[0] - 1
xmitte = xmax / 2
ymax = termsize_xy[1] ymax = termsize_xy[1]
ymin = 0
# CTRL and ESC-codes for the used outputdevice. Probably a terminal. xmin = 0
clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h"
# pi is not defined by default # pi is not defined by default
pi = 3.1416 pi = 3.1416
deg2rad = pi / 180 deg2rad = pi / 180
# position cursor at x,y - where x=0 y=0 is the left lower corner like in mathematical diagrams # position cursor at x,y - where x=0 y=0 is the left lower corner like in mathematical diagrams
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)
# 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"
# some scales, we need # some scales, we need
# not everything has to be recomputed in loops. # not everything has to be recomputed in loops.
angle = 80 * deg2rad
sinangle = sin(angle)
cosangle = cos(angle)
power = sin(50 * deg2rad)
xsteps = xmax xsteps = xmax
gravitation = 10
x = 0 x = 0
y = x**2 y = x**2
starthoehe = 0
startwinkel = 45
startgeschwindigkeit = 23
erde = 9.81
mond = 1.6
jupiter = 24
gravitation = erde
#########################
starthoehe = float(input("Starthöhe: "))
startwinkel = float(input("Startwinkel: ")) * deg2rad
startgeschwindigkeit = float(input("Startgeschwindigkeit: "))
# Calculate time of flight
flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation
# Calculate maximum height
hoehe = 0.5 * gravitation * flugdauer**2 + starthoehe
# calculate length of flight
wurfweite = (
startgeschwindigkeit
* cos(startwinkel)
* (startgeschwindigkeit * sin(startwinkel) + sqrt(startgeschwindigkeit**2 * sin(startwinkel) ** 2 + 2 * gravitation * starthoehe))
) / gravitation
# init screen and wait for userinput # init screen and wait for userinput
print(clear, curoff) print(clear, curoff)
print(xsteps) print(
"xteps: ",
xsteps,
"\nwurfweite: ",
wurfweite,
"\nstartwinkel: ",
startwinkel,
"\nstartgeschwindigkeit: ",
startgeschwindigkeit,
"\nstarthroehe: ",
starthoehe,
"hoehe: ",
hoehe,
)
a = input("CR please:") a = input("CR please:")
# position cursor down left corner
curpos(1, ymax) curpos(1, ymax)
# cowlenght ist 2, is cow is an UTF8-Icon, otherwise 1
for x in range(1, xsteps, cowlength): for x in range(1, xsteps, cowlength):
# parameters to fit the screen # the formula, which genereates the y position for the corresponding x
y = (x - xmitte) ** 2 /xmitte y = (-(gravitation / (2 * startgeschwindigkeit**2 * cos(startwinkel) ** 2)) * x**2) + (tan(startwinkel) * x + starthoehe)
if y < ymax:
curpos(x, ymax- y) # Ensure, that nothing has to be drawn outside the viewport
if y < ymax and y > ymin:
curpos(x, y)
print(cow, end="") print(cow, end="")
time.sleep(0.01) time.sleep(0.01)
curpos(1, 1) curpos(1, 1)
sys.exit(curon + "Schulz nun.") sys.exit(curon + "Moooooooooooo.")