2023-11-11 20:55:24 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import os, sys, termios, tty, time, random
|
2023-11-13 19:11:51 +01:00
|
|
|
from math import sin, cos, tan, sqrt
|
2023-11-11 20:55:24 +01:00
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
# Randomly choose a cow
|
|
|
|
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
|
2023-11-13 13:47:02 +01:00
|
|
|
cowlistlength = len(cows)
|
|
|
|
cow = cows[random.randint(0, cowlistlength - 1)]
|
2023-11-13 19:11:51 +01:00
|
|
|
cowlength = len(cow)
|
2023-11-11 20:55:24 +01:00
|
|
|
|
|
|
|
# Needed: find our screensize
|
|
|
|
termsize_xy = os.get_terminal_size()
|
|
|
|
xmax = termsize_xy[0] - 1
|
|
|
|
ymax = termsize_xy[1]
|
2023-11-13 19:11:51 +01:00
|
|
|
ymin = 0
|
|
|
|
xmin = 0
|
2023-11-14 16:04:03 +01:00
|
|
|
xold = xmin
|
2023-11-11 20:55:24 +01:00
|
|
|
|
|
|
|
# pi is not defined by default
|
|
|
|
pi = 3.1416
|
|
|
|
deg2rad = pi / 180
|
2023-11-13 19:11:51 +01:00
|
|
|
|
2023-11-11 20:55:24 +01:00
|
|
|
# position cursor at x,y - where x=0 y=0 is the left lower corner like in mathematical diagrams
|
|
|
|
def curpos(x, y):
|
|
|
|
print("\033[%d;%dH" % (ymax - y, x), end="", flush=True)
|
|
|
|
|
|
|
|
|
2023-11-14 16:04:03 +01:00
|
|
|
outputfile = open("cowyeetflugbahn.txt", "w")
|
|
|
|
|
2023-11-13 19:11:51 +01:00
|
|
|
# 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"
|
|
|
|
|
|
|
|
|
2023-11-11 20:55:24 +01:00
|
|
|
# some scales, we need
|
|
|
|
# not everything has to be recomputed in loops.
|
|
|
|
xsteps = xmax
|
|
|
|
x = 0
|
|
|
|
y = x**2
|
2023-11-13 19:11:51 +01:00
|
|
|
erde = 9.81
|
|
|
|
mond = 1.6
|
|
|
|
jupiter = 24
|
|
|
|
gravitation = erde
|
2023-11-14 01:25:31 +01:00
|
|
|
# in scala the resulting coordinates will be returned
|
|
|
|
scala = []
|
2023-11-13 19:11:51 +01:00
|
|
|
|
2023-11-14 01:25:31 +01:00
|
|
|
# used, if input is disabled
|
|
|
|
starthoehe = 0
|
2023-11-14 16:04:03 +01:00
|
|
|
startwinkel = 26 * deg2rad
|
|
|
|
startgeschwindigkeit = 36
|
|
|
|
loeschen = "y"
|
|
|
|
|
|
|
|
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)")
|
2023-11-14 01:25:31 +01:00
|
|
|
####
|
2023-11-13 19:11:51 +01:00
|
|
|
|
|
|
|
# Calculate time of flight
|
|
|
|
flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation
|
2023-11-14 16:04:03 +01:00
|
|
|
schlafdauer = flugdauer / xmax
|
2023-11-13 19:11:51 +01:00
|
|
|
# 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
|
|
|
|
|
2023-11-11 20:55:24 +01:00
|
|
|
|
|
|
|
# init screen and wait for userinput
|
2023-11-13 19:11:51 +01:00
|
|
|
|
2023-11-11 20:55:24 +01:00
|
|
|
print(clear, curoff)
|
2023-11-13 19:11:51 +01:00
|
|
|
print(
|
|
|
|
"xteps: ",
|
|
|
|
xsteps,
|
|
|
|
"\nwurfweite: ",
|
|
|
|
wurfweite,
|
|
|
|
"\nstartwinkel: ",
|
2023-11-14 01:25:31 +01:00
|
|
|
startwinkel / deg2rad,
|
2023-11-13 19:11:51 +01:00
|
|
|
"\nstartgeschwindigkeit: ",
|
|
|
|
startgeschwindigkeit,
|
2023-11-14 01:25:31 +01:00
|
|
|
"\nstarthoehe: ",
|
2023-11-13 19:11:51 +01:00
|
|
|
starthoehe,
|
2023-11-14 01:25:31 +01:00
|
|
|
"\nhoehe: ",
|
2023-11-13 19:11:51 +01:00
|
|
|
hoehe,
|
2023-11-14 16:04:03 +01:00
|
|
|
"\nschlafdauer: ",
|
|
|
|
schlafdauer,
|
2023-11-13 19:11:51 +01:00
|
|
|
)
|
|
|
|
|
2023-11-14 01:25:31 +01:00
|
|
|
bla = input("CR please:")
|
2023-11-11 20:55:24 +01:00
|
|
|
|
2023-11-13 19:11:51 +01:00
|
|
|
# position cursor down left corner
|
2023-11-11 20:55:24 +01:00
|
|
|
curpos(1, ymax)
|
2023-11-13 19:11:51 +01:00
|
|
|
|
2023-11-14 01:25:31 +01:00
|
|
|
# cowlength is 2, if cow is an UTF8-Icon, otherwise 1
|
2023-11-14 16:04:03 +01:00
|
|
|
for x in range(xmin, xsteps - 1, cowlength):
|
2023-11-14 01:25:31 +01:00
|
|
|
# the formula, which generates the y position for the corresponding x, shamelessly ripped from some schoolbook and modified.
|
|
|
|
yold = y
|
2023-11-13 19:11:51 +01:00
|
|
|
y = (-(gravitation / (2 * startgeschwindigkeit**2 * cos(startwinkel) ** 2)) * x**2) + (tan(startwinkel) * x + starthoehe)
|
|
|
|
|
2023-11-14 16:04:03 +01:00
|
|
|
time.sleep(schlafdauer)
|
2023-11-13 19:11:51 +01:00
|
|
|
# Ensure, that nothing has to be drawn outside the viewport
|
|
|
|
if y < ymax and y > ymin:
|
|
|
|
curpos(x, y)
|
2023-11-11 20:55:24 +01:00
|
|
|
print(cow, end="")
|
2023-11-14 01:25:31 +01:00
|
|
|
# Stash awa the coordinates into scala, which will be returned
|
|
|
|
scala += [x, int(y * 10 + 5) / 10]
|
|
|
|
if loeschen == "y":
|
2023-11-14 16:04:03 +01:00
|
|
|
curpos(xold, yold)
|
|
|
|
print(" ", end="")
|
|
|
|
else:
|
|
|
|
scala += [x, 0]
|
2023-11-11 20:55:24 +01:00
|
|
|
|
2023-11-14 16:04:03 +01:00
|
|
|
xold = x
|
2023-11-11 20:55:24 +01:00
|
|
|
|
2023-11-14 01:25:31 +01:00
|
|
|
curpos(0, 0)
|
2023-11-14 16:04:03 +01:00
|
|
|
outputfile.write(str(scala))
|
2023-11-13 19:11:51 +01:00
|
|
|
sys.exit(curon + "Moooooooooooo.")
|