Made it usable as module.

This commit is contained in:
The Wobbler 2023-12-29 18:54:39 +01:00
parent d085bd72af
commit b8369e0bf8

View file

@ -56,54 +56,57 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk
# some useful control # some useful control
clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h" clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h"
# set position of cursor # set position of cursor
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)
# Randomly choose a cow if __name__ == "__main__":
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕" # Randomly choose a cow
cowlistlength = len(cows) cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
cow = cows[random.randint(0, cowlistlength - 1)] cowlistlength = len(cows)
# pi is not defined by default cow = cows[random.randint(0, cowlistlength - 1)]
pi = 3.1416 # pi is not defined by default
deg2rad = pi / 180 pi = 3.1416
deg2rad = pi / 180
# Needed: find our screensize. We are in textmode here # Needed: find our screensize. We are in textmode here
termsize_xy = os.get_terminal_size() 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 # X-Resolution of the display
xmax = termsize_xy[0] - 1 xmax = termsize_xy[0] - 1
xsteps = xmax xsteps = xmax
ymax = termsize_xy[1] ymax = termsize_xy[1]
ymin = 0 ymin = 0
xmin = 0 xmin = 0
startwinkel = 34 startwinkel = 34
startgeschwindigkeit = 31 startgeschwindigkeit = 31
starthoehe = 0 starthoehe = 0
schlafzeit = 0.05 schlafzeit = 0.05
### ###
# needed for erasing ol position # needed for erasing ol position
xold = xmin xold = xmin
yold = ymin yold = ymin
x = xmin x = xmin
y = xmin y = xmin
# Call the function, which calculates the coordinates) # Call the function, which calculates the coordinates)
ergebnis = berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe) ergebnis = berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe)
print(curoff) print(curoff)
# here we draw the cow # here we draw the cow
for count in range(xmin, len(ergebnis), 2): for count in range(xmin, len(ergebnis), 2):
xold, yold = x, y xold, yold = x, y
x, y = ergebnis[count], ergebnis[count + 1] x, y = ergebnis[count], ergebnis[count + 1]
curpos(x, y) curpos(x, y)
print(cow, end="") print(cow, end="")
sleep(schlafzeit) sleep(schlafzeit)
curpos(xold, yold) curpos(xold, yold)
print("☁️ ", end="") print("☁️ ", end="")
sys.exit(home + cow + curon) sys.exit(home + cow + curon)