From b8369e0bf814c91000cdd9fad80e5a6e33530538 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Fri, 29 Dec 2023 18:54:39 +0100 Subject: [PATCH] Made it usable as module. --- physics/parabelfunc.py | 81 ++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/physics/parabelfunc.py b/physics/parabelfunc.py index 63b7b50..5cafa06 100755 --- a/physics/parabelfunc.py +++ b/physics/parabelfunc.py @@ -56,54 +56,57 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk # some useful control clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h" + + # set position of cursor def curpos(x, y): print("\033[%d;%dH" % (ymax - y, x), end="", flush=True) -# Randomly choose a cow -cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕" -cowlistlength = len(cows) -cow = cows[random.randint(0, cowlistlength - 1)] -# pi is not defined by default -pi = 3.1416 -deg2rad = pi / 180 +if __name__ == "__main__": + # Randomly choose a cow + cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕" + cowlistlength = len(cows) + cow = cows[random.randint(0, cowlistlength - 1)] + # pi is not defined by default + pi = 3.1416 + deg2rad = pi / 180 -# Needed: find our screensize. We are in textmode here -termsize_xy = os.get_terminal_size() + # 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 ### + ### 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 -ymax = termsize_xy[1] -ymin = 0 -xmin = 0 -startwinkel = 34 -startgeschwindigkeit = 31 -starthoehe = 0 -schlafzeit = 0.05 -### + # X-Resolution of the display + xmax = termsize_xy[0] - 1 + xsteps = xmax + ymax = termsize_xy[1] + ymin = 0 + xmin = 0 + startwinkel = 34 + startgeschwindigkeit = 31 + starthoehe = 0 + schlafzeit = 0.05 + ### -# needed for erasing ol position -xold = xmin -yold = ymin -x = xmin -y = xmin + # needed for erasing ol position + xold = xmin + yold = ymin + x = xmin + y = xmin -# Call the function, which calculates the coordinates) -ergebnis = berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe) -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="") + # Call the function, which calculates the coordinates) + ergebnis = berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe) + 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="") -sys.exit(home + cow + curon) + sys.exit(home + cow + curon)