great update # aber komme mit wuffels parrable funktion nicht klar

This commit is contained in:
Michael S. 2024-01-13 19:55:47 +01:00
parent e49d31babc
commit d4aa1c12bb
16 changed files with 542 additions and 74 deletions

Binary file not shown.

61
physics/kreis.py Normal file
View file

@ -0,0 +1,61 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys, termios, tty, time, random
from math import sin, cos, sqrt
from time import sleep
# Randomly choose a cow
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
cowslength = len(cows)
cow = cows[random.randint(0, cowslength - 1)]
# cow = "🐄"
# cow = "*"
if cow.isascii():
charlength = 1
else:
charlength = 2
# Needed: find our screensize
termsize_xy = os.get_terminal_size()
# maximum and medium of points in a row
xmax = termsize_xy[0] - 1
xmitte = xmax / 2
# maximum and medium of points in a column
ymax = termsize_xy[1]
ymitte = ymax / 2
# 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"
# pi is not defined by default. Noone has a display with 31416 Pixels in a row. U know better? Enhance it.
pi = 3.1416
# This is for convenience, if you are thinking in degrees. It must not be recalculated every loop.
deg2rad = pi / 180
# position cursor at x,y - where x=0 y=0 is the left lower corner like in mathematical diagrams
# some scales, we need. Those UTF8Cows are 2 chars wide and need more space. So we have to scale one Axis
radius = ymitte - 2
xradius = ymitte * charlength - 1
# Position the curser at x,y. Yes, we start with x, print does not, you are looking right. Leave it this way!
def curpos(x, y):
print("\033[%d;%dH" % (ymax - y, x), end="", flush=True)
print(clear, curoff)
# Draw a circle in maximum 360 Steps, one for for every degree
for winkel in range(0, 359):
x = sin(winkel * deg2rad) * xradius + xmitte
y = cos(winkel * deg2rad) * radius + ymitte
curpos(x, y)
print(cow, end="")
time.sleep(0.01)
curpos(1, 1)
sys.exit(curon + "Schulz nun.")

128
physics/parabelfunc.py Normal file
View file

@ -0,0 +1,128 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys, random #,termios, tty, time,
from math import sin, cos, tan, sqrt
from time import sleep
# pi is not defined by default
pi = 3.1416
deg2rad = pi / 180
########################################################################################
def berechneflugbahn(xmax, ymax, steps, startwinkel, startgeschwindigkeit, xmin=0, ymin=0, starthoehe=0, gravitation=9.81, xstep=1):
x = 0
y = x**2
# in scala the resulting coordinates will be returned
scala = []
startwinkel = startwinkel * deg2rad
# Calculate time of flight, actually not used
flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation
# Calculate maximum height
hoehe = 0.5 * gravitation * flugdauer**2 + starthoehe
# calculate length of flight, actually not used
wurfweite = (
startgeschwindigkeit
* cos(startwinkel)
* (startgeschwindigkeit * sin(startwinkel) + sqrt(startgeschwindigkeit**2 * sin(startwinkel) ** 2 + 2 * gravitation * starthoehe))
) / gravitation
first_run = True
# cowlength is 2, if cow is an UTF8-Icon, otherwise 1
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.
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 x >= xmax:
x = xmax
if y >= ymax:
y = ymax
elif y <= ymin:
y = ymin
# Stash away the coordinates into scala, which will be returned
scala += [x, int((y * 100 + 50) / 100)]
if y == ymin and not first_run:
break
first_run = False
return scala
#############################################################################################
# berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe):
# some useful control
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
def curpos(x, y):
print("\033[%d;%dH" % (ymax - y, x), end="", flush=True)
if __name__ == "__main__":
# Randomly choose a cow
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
cowlistlength = len(cows)
cow = cows[random.randint(0, cowlistlength - 1)]
# Needed: find our screensize. We are in textmode here
termsize_xy = os.get_terminal_size()
### I m p o r t a n t p a r a m e t e r s ###
# X-Resolution of the display
xmax = termsize_xy[0] - 1
xsteps = xmax * 2
ymax = termsize_xy[1]
ymin = 0
xmin = 0
startwinkel = 34
startgeschwindigkeit = 60
starthoehe = 0
schlafzeit = 0.05
###
# needed for erasing old position
xold = xmin
yold = ymin
x = xmin
y = xmin
# Call the function, which calculates the coordinates)
ergebnis = berechneflugbahn(xmax, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe, gravitation=g_erde, xstep=2)
print(curoff)
# here we draw the cow
for count in range(xmin, len(ergebnis), 2):
xold, yold = x, y
x, y = ergebnis[count], ergebnis[count + 1]
curpos(x, y)
print(cow, end="")
sleep(schlafzeit)
curpos(xold, yold)
print("☁️ ", end="")
sleep(2)
sys.exit(home + curon)

128
physics/parabeltest.py Normal file
View file

@ -0,0 +1,128 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys, termios, tty, time, random
from math import sin, cos, tan, sqrt
from time import sleep
# Randomly choose a cow
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
cowlistlength = len(cows)
cow = cows[random.randint(0, cowlistlength - 1)]
cowlength = len(cow)
# Needed: find our screensize
termsize_xy = os.get_terminal_size()
xmax = termsize_xy[0] - 1
ymax = termsize_xy[1]
ymin = 0
xmin = 0
xold = xmin
# pi is not defined by default
pi = 3.1416
deg2rad = pi / 180
# 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)
outputfile = open("cowyeetflugbahn.txt", "w")
# 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
# not everything has to be recomputed in loops.
xsteps = xmax
x = 0
y = x**2
erde = 9.81
mond = 1.6
jupiter = 24
gravitation = erde
# in scala the resulting coordinates will be returned
scala = []
# used, if input is disabled
starthoehe = 0
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)")
####
# 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
# init screen and wait for userinput
print(clear, curoff)
print(
"xteps: ",
xsteps,
"\nwurfweite: ",
wurfweite,
"\nstartwinkel: ",
startwinkel / deg2rad,
"\nstartgeschwindigkeit: ",
startgeschwindigkeit,
"\nstarthoehe: ",
starthoehe,
"\nhoehe: ",
hoehe,
"\nschlafdauer: ",
schlafdauer,
)
bla = input("CR please:")
# position cursor down left corner
curpos(1, ymax)
# 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)
time.sleep(schlafdauer)
# Ensure, that nothing has to be drawn outside the viewport
if y < ymax and y > ymin:
curpos(x, y)
print(cow, end="")
# Stash awa the coordinates into scala, which will be returned
scala += [x, int(y * 10 + 5) / 10]
if loeschen == "y":
curpos(xold, yold)
print(" ", end="")
else:
scala += [x, 0]
xold = x
curpos(0, 0)
outputfile.write(str(scala))
sys.exit(curon + "Moooooooooooo.")