From 2d1c8f7d19e1f8d38a8a35afc6b9e5f064bf78b1 Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Sun, 19 Nov 2023 17:29:23 +0100 Subject: [PATCH 1/7] Funktioniert, mit Meispiel --- parabelfunc.py | 61 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/parabelfunc.py b/parabelfunc.py index 4684850..4c18d7b 100755 --- a/parabelfunc.py +++ b/parabelfunc.py @@ -6,7 +6,7 @@ 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 @@ -17,6 +17,7 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk jupiter = 24 gravitation = erde startwinkel = startwinkel * deg2rad + cowlength = len(cow) + 1 # Calculate time of flight flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation @@ -38,33 +39,63 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk 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: + if y <= ymax and y >= ymin: # Stash awa the coordinates into scala, which will be returned - scala += [x, int(y * 10 + 5) / 10] + scala += [x, int((y * 100 + 50) / 100)] else: - scala += [x, 0] + scala += [0, 0] xold = x return scala +###################################################### # berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe): +# set position of cursor +def curpos(x, y): + print("\033[%d;%dH" % (ymax - y, x), end="", flush=True) -cow = "🦝" -cowlength = len(cow) -xmax = 157 -ymax = 38 -ymin = 0 -xmin = 0 -xold = xmin + +# 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() + +### 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 -wurfweite = 0 -startwinkel = 34 -startgeschwindigkeit = 23 +ymax = termsize_xy[1] +ymin = 0 +xmin = 0 +startwinkel = 34 +startgeschwindigkeit = 31 starthoehe = 0 -print(berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe)) +### + +# 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) + +# 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="") + curpos(xold, yold) +bla = input("CR please...") From 0432b4e4f1e1b55f852a7839efdfb0f74ef0a179 Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Sun, 19 Nov 2023 17:59:57 +0100 Subject: [PATCH 2/7] Some more content concerning the added parabel funktions --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 16fb308..abcb392 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,23 @@ and returns a list of x and y coordinates: [x1,y1,x2,y2....] like the following The parameter cow is not useless, it can be set to any singlebyte ASCII string like "*" or some doublespaced UTF8 char like "🐄". If it is a singlechar in ASCII, which is the default, the curve will be calculated with singlesteps, if ist is a UTF8-String, each step will be 2 points, because we now know, we have a textmode display and doublewidth chars. +``` + # X-Resolution of the display + + xmax = 100 + ymax = 40 + ymin = 0 + xmin = 0 + startwinkel = 34 + startgeschwindigkeit = 31 + starthoehe = 0 + +ergebnis = berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe) + +for count in range(xmin, len(ergebnis), 2): + x, y = ergebnis[count], ergebnis[count + 1] + curpos(x, y) + print(cow, end="") + +``` From cbf7eb60d7d0b65cfa621e5f1b44af6292cdc9ec Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Sun, 19 Nov 2023 18:01:30 +0100 Subject: [PATCH 3/7] Funktioniert, mit Beispiel --- parabelfunc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/parabelfunc.py b/parabelfunc.py index 4c18d7b..fc9825c 100755 --- a/parabelfunc.py +++ b/parabelfunc.py @@ -98,4 +98,5 @@ for count in range(xmin, len(ergebnis), 2): curpos(x, y) print(cow, end="") curpos(xold, yold) + print(".",end="") bla = input("CR please...") From 3d16287c44b0d26a7cdd944c1003dbf3a21ebf2c Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Sun, 19 Nov 2023 18:25:08 +0100 Subject: [PATCH 4/7] Some more content concerning the added parabel funktions --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index abcb392..fb8e91b 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The parameter cow is not useless, it can be set to any singlebyte ASCII string l ``` # X-Resolution of the display + cow="🐫" xmax = 100 ymax = 40 ymin = 0 From e41552291689aa02ba0d23774fd4d9055940b1e7 Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Sun, 19 Nov 2023 18:53:07 +0100 Subject: [PATCH 5/7] Fehler beseitigt --- parabelfunc.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/parabelfunc.py b/parabelfunc.py index fc9825c..5dc2770 100755 --- a/parabelfunc.py +++ b/parabelfunc.py @@ -6,7 +6,7 @@ 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 @@ -35,12 +35,11 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk # 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 + # Stash away the coordinates into scala, which will be returned scala += [x, int((y * 100 + 50) / 100)] else: scala += [0, 0] @@ -50,7 +49,7 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk return scala -###################################################### +############################################################################################# # berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigkeit, starthoehe): # set position of cursor From a71b8885e0f8a37d27cbff90b7cf98161155276d Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Mon, 20 Nov 2023 14:49:07 +0100 Subject: [PATCH 6/7] Fehler beseitigt --- parabelfunc.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/parabelfunc.py b/parabelfunc.py index 5dc2770..ee2acce 100755 --- a/parabelfunc.py +++ b/parabelfunc.py @@ -17,15 +17,17 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk jupiter = 24 gravitation = erde startwinkel = startwinkel * deg2rad - cowlength = len(cow) + 1 + if cow.isascii(): + cowlength = 1 + else: + cowlength = 1 - # Calculate time of flight + # Calculate time of flight, actually not used flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation - schlafdauer = flugdauer / xmax # Calculate maximum height hoehe = 0.5 * gravitation * flugdauer**2 + starthoehe - # calculate length of flight + # calculate length of flight, actually not used wurfweite = ( startgeschwindigkeit * cos(startwinkel) @@ -52,6 +54,8 @@ def berechneflugbahn(cow, xmin, xmax, ymin, ymax, startwinkel, startgeschwindigk ############################################################################################# # 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" # set position of cursor def curpos(x, y): print("\033[%d;%dH" % (ymax - y, x), end="", flush=True) @@ -79,6 +83,7 @@ xmin = 0 startwinkel = 34 startgeschwindigkeit = 31 starthoehe = 0 +schlafzeit = 0.1 ### # needed for erasing ol position @@ -89,7 +94,7 @@ 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 @@ -97,5 +102,7 @@ for count in range(xmin, len(ergebnis), 2): curpos(x, y) print(cow, end="") curpos(xold, yold) - print(".",end="") + sleep(schlafzeit) + print("☁️ ", end="") bla = input("CR please...") +sys.exit(cow+curon) From 818c88e050c4b9acc56cb3c02a70a83c5f3cd67f Mon Sep 17 00:00:00 2001 From: Wolfgang Nowak Date: Mon, 20 Nov 2023 15:11:26 +0100 Subject: [PATCH 7/7] =?UTF-8?q?aufgeh=C3=BCbscht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parabelfunc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/parabelfunc.py b/parabelfunc.py index ee2acce..63b7b50 100755 --- a/parabelfunc.py +++ b/parabelfunc.py @@ -83,7 +83,7 @@ xmin = 0 startwinkel = 34 startgeschwindigkeit = 31 starthoehe = 0 -schlafzeit = 0.1 +schlafzeit = 0.05 ### # needed for erasing ol position @@ -101,8 +101,9 @@ for count in range(xmin, len(ergebnis), 2): x, y = ergebnis[count], ergebnis[count + 1] curpos(x, y) print(cow, end="") - curpos(xold, yold) sleep(schlafzeit) + curpos(xold, yold) print("☁️ ", end="") -bla = input("CR please...") -sys.exit(cow+curon) + + +sys.exit(home + cow + curon)