72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
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):
|
|
x = 0
|
|
y = x**2
|
|
# in scala the resulting coordinates will be returned
|
|
scala = []
|
|
erde = 9.81
|
|
mond = 1.6
|
|
jupiter = 24
|
|
gravitation = erde
|
|
starthoehe = 0
|
|
startwinkel = 26 * deg2rad
|
|
startgeschwindigkeit = 36
|
|
loeschen = "y"
|
|
|
|
# Calculate time of flight
|
|
flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation
|
|
schlafdauer = flugdauer / xmax
|
|
# 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
|
|
|
|
# cowlength is 2, if cow is an UTF8-Icon, otherwise 1
|
|
for x in range(xmin, xsteps - 1, cowlength):
|
|
# the formula, which generates the y position for the corresponding x, shamelessly ripped from some schoolbook and modified.
|
|
yold = y
|
|
y = (-(gravitation / (2 * startgeschwindigkeit**2 * cos(startwinkel) ** 2)) * x**2) + (tan(startwinkel) * x + starthoehe)
|
|
|
|
# Ensure, that nothing has to be drawn outside the viewport
|
|
if y < ymax and y > ymin:
|
|
# Stash awa the coordinates into scala, which will be returned
|
|
scala += [x, int(y * 10 + 5) / 10]
|
|
else:
|
|
scala += [x, 0]
|
|
|
|
xold = x
|
|
|
|
return scala
|
|
|
|
|
|
# berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe):
|
|
|
|
cow = "🦝"
|
|
cowlength = len(cow)
|
|
xmax = 157
|
|
ymax = 38
|
|
ymin = 0
|
|
xmin = 0
|
|
xold = xmin
|
|
# pi is not defined by default
|
|
pi = 3.1416
|
|
deg2rad = pi / 180
|
|
xsteps = xmax
|
|
wurfweite = 0
|
|
startwinkel = (34 / deg2rad,)
|
|
startgeschwindigkeit = 23
|
|
starthoehe = 0
|
|
print(berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe))
|