From d83e2f7232c17a667ab75e996172d61cf33f094e Mon Sep 17 00:00:00 2001 From: Megamichi Date: Mon, 15 Jan 2024 20:38:06 +0100 Subject: [PATCH] =?UTF-8?q?engine=20umschmwei=C3=9Fen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__pycache__/parabelfunc.cpython-311.pyc | Bin 3758 -> 3743 bytes physics/parabelfunc.py | 2 +- tengine/__pycache__/main.cpython-311.pyc | Bin 4061 -> 4653 bytes tengine/main.py | 87 ++++++------- v2.py | 116 ++++++++---------- 5 files changed, 97 insertions(+), 108 deletions(-) diff --git a/physics/__pycache__/parabelfunc.cpython-311.pyc b/physics/__pycache__/parabelfunc.cpython-311.pyc index 2c8f50e21c0ab8fb7478299d0bc156ce03e06ade..d3f4d4b72dbd718794be66d540b30a123c1dbe59 100644 GIT binary patch delta 108 zcmZ1{J71P}IWI340}x23E=?`k$Scjv=(bst*_d&163azi)+$y8h7`6cpnMAJWCvD# z1@>Bjo`xEpUR26xJ|C#?zBuv%O&#y~wM6g;#y^Bla_F E06Ie(3IG5A delta 124 zcmbO)yH1vOIWI340}#wUv^X_;Bd;_wqt9kdW@ARS6xJ%B#N-&3i@a=AtPBh(>{UQz zDQuIiSoKvoY6W^4YIuSfG&%i>n1JFhK}0$b1Hl9PkRp(on>$&<7#Yt`e!%vITX3f2 S0@sVYT32|rHeY5x!v+BJbRNwB diff --git a/physics/parabelfunc.py b/physics/parabelfunc.py index 3f8b7ce..2aee903 100644 --- a/physics/parabelfunc.py +++ b/physics/parabelfunc.py @@ -37,7 +37,7 @@ def berechneflugbahn(xmax, ymax, steps, startwinkel, startgeschwindigkeit, xmin= first_run = True # cowlength is 2, if cow is an UTF8-Icon, otherwise 1 - for x in range(xmin, steps - 1, xstep): + for x in range(xmin, steps , xstep):#steps - 1 # 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) diff --git a/tengine/__pycache__/main.cpython-311.pyc b/tengine/__pycache__/main.cpython-311.pyc index 8b0aacfb65ca55c71c2d322aa45e303b6ef13b90..14890401d4d7fd6a03d39f6a5f06eccc0375323a 100644 GIT binary patch literal 4653 zcma(UTWk~A_1>AWGtSF4NeFBb)*)mQladDuy9KflrYUp_8;RY&h?V7d24}#r!yWT7 zPB$M^@*+zFDHUERRIZezj-XOL`az{u+J3ZO{qR&)YmJ1oQora|D*Bb5_MAH&XC?vK z$>hv^oO91T@8e&$wKWrXw6DKa|K=s+A2_iesXlnU2!qE&Aqq{B1v*P95r|5k!s;^{ zms}I<;T!fudruLvz%MS$O0yn;Tp)^gpD5B(pncY$pYth3?|e}G^4Tw zEfq^fbuFvDLfp80CVp+=*Oy@On5blyDr8nr{J=n(6&2||nU$1);=NC2JxUYIyowC4 zN$~-cm1clGC8)H*ezUSqX@_r%BEU5|%%+T*N@yw7^fEPblci?j)WO;VV-)Z8=bW=b z?~{yUKV#nvc0qW6Pht0217n)F)tDpE28BX^zvyNMHX>DJ>I?j!q`i@mNxyf`N_Y7&gI$^aB8vN#($}^_GIgj>hCQ?2)iw zdRQ!#P)#9ohqWV(B?$|{n4$35BlT;&lQU;`4A6mH_j&8xylgT1R{hPnUuo+a%!~u$ zRk)3f!BE8vqbw}4PWZqz?wVdb&QvwEK}|_llUH?gl@Py>DcjO#1G{g9exVNnSSB@o z{vQVaBz!mVN9lJXzaIgPM)&z@_xZe3XvxDL=j^gL-h#Wa6+liG&XH2XT>-1{xE)ua z&joiJQ^*+HfwyTJNF%B#1r@%?v{c6Q=^17T%Fs*>DcSol&$ihDa&#Y}Skk?e+w#i8 z)Pt1KeyG}hsC1$t4;%7uRUU?c^;&vu1)6vxmSBQL;v)VN29F_dO7PwLxW%F*gEaLg zgVA1pa^zZL#~ots*);iba!L4qPEqJV`|w>^V$X^Dmc$%&-XJIJ(B{NRIH%B2_=Fok zm|>`fuw;4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`O~P(0NyddKpD9EM5pOK|1T6f-;sE}!_ep$W|RzZ z9+hlcmS;0eQ5kmv7S$~J;7E9v6&72Xv1c*#<9+bxe*p5z5KldW5WzizdAip-P;D8= zOZg8Az9L<3EB>k+DgCpqUW3)7C2Ew&Kn6G>N;-1oP$}wF0AIY1K z{Qg#M{Il_5Wc^lt{LqXKXm1?R*CdG_J*!^sPpDIM zb^qqU9}0(W0i-y-yg15@sJHMgDvDtW3mCy%H0rDSY~6@4V+K5m%!u3=fUY{;ZWA^nvwJA@+ ziVrusOWl}rVK-7py++0x{sIJkt`aeWy^u;*KH6S<^xNGrv;SSwKV0<>V@~!yJxt1` z7-oNPr4jq}9=J2stlQ9hH-vWWdQTmL8tM0nj(phckG+VlASbMAe!%)rst2L}Q zzFai>-^+P&LhhY?iPGyJkp}Tf^w>Ue6F;TDK&c&4Sk!|Zb>gKI(a<2?R@|dWPE*>2 Tqjlo-;i#L0+zj3Pxoi9%3Z^Y~ diff --git a/tengine/main.py b/tengine/main.py index 16e6d27..aa7f3c8 100644 --- a/tengine/main.py +++ b/tengine/main.py @@ -2,51 +2,52 @@ from os import get_terminal_size tx,ty = get_terminal_size().columns ,get_terminal_size().lines-2 -def genfeld(): - return [[' ' for _ in range(tx)] for _ in range(ty+2)] +class tengine(): + def __init__(self) -> None: + self.screen = [[' ' for _ in range(tx)] for _ in range(ty+2)] -def bg_char(feld, char=' '): - for a in range(len(feld)): - for b in range(len(feld[0])): - feld[a][b] = char - return feld + def print(self): + print(self.strscreen(),end="\r") -def strfeld(feld): - return '\n'.join([''.join(row) for row in feld]).lstrip('\n').rstrip('\n') -def prfeld(feld): - print(strfeld(feld),end="\r") + def bg_char(self, char=' '): + self.prfeld() + for a in range(len(self.screen)): + for b in range(len(self.screen[0])): + self.screen[a][b] = char + + + def strscreen(self): + back = "" + for a in self.screen: + line = "" + for b in a: + line += str(b) + back += line[:tx] + "\n" + return back.lstrip('\n').rstrip('\n') + -def change_char(feld, character, position): - feld[position[0]][position[1]] = character + def set_char(self, character, position): + self.screen[position[0]][position[1]] = character + + def set_block(self, block, position): + position = [position[0]+1,position[1]] + pposition = position + for zeichen in block: + if zeichen == '\n': + pposition = [pposition[0] + 1, position[1]] + else: + pposition = [pposition[0], pposition[1] + 1] + self.screen[pposition[0]][pposition[1]] = zeichen -def change_block(feld, block, position): - position = [position[0]+1,position[1]] - pposition = position - for zeichen in block: - if zeichen == '\n': - pposition = [pposition[0] + 1, position[1]] - else: - pposition = [pposition[0], pposition[1] + 1] - feld[pposition[0]][pposition[1]] = zeichen - return feld + def clear(self): + print('\033c', end='') -def clear(): - print('\033c', end='') - -def draw_border(feld, border_char='+'): - for i in range(len(feld)): - feld[i][0] = feld[i][-1] = border_char - for j in range(len(feld[0])): - feld[0][j] = feld[-1][j] = border_char - global tx,ty - tx -= 2;ty -= 2 - return feld - -#def move_cursor(x, y): -# print(f'\033[{y};{x}H', end='') - -def viereck(feld, start_pos, width, height, fill_char='#'): - for i in range(height): - for j in range(width): - feld[start_pos[0]+1 + i][start_pos[1] + j] = fill_char - return feld + def draw_border(self, border_char='+'): + for i in range(len(self.screen)): + self.screen[i][0] = self.screen[i][-1] = border_char + for j in range(len(self.screen[0])): + self.screen[0][j] = self.screen[-1][j] = border_char + def viereck(self, start_pos, width, height, fill_char='#'): + for i in range(height): + for j in range(width): + self.screen[start_pos[0]+1 + i][start_pos[1] + j] = fill_char \ No newline at end of file diff --git a/v2.py b/v2.py index c808843..501e403 100644 --- a/v2.py +++ b/v2.py @@ -1,9 +1,9 @@ #!/usr/bin/python3 #import os -from tengine.main import *#ty,tx,clear,genfeld,strfeld,change_char,bg_char +from tengine.main import *#ty,tx,scene.clear,genscene,strscene,change_char,bg_char from pynput import keyboard from time import sleep -#from physics.parabelfunc import berechneflugbahn +from physics.parabelfunc import berechneflugbahn import ascii import random @@ -37,40 +37,40 @@ if not ty >= 11 : print("please resize you teerminal over 11 lines") if __name__ == "__main__" and running == True: - feld = genfeld() - feld = change_block(feld,ascii.logo,[0,int(tx/2-21)]) + scene = tengine() + scene.set_block(ascii.logo,[0,int(tx/2-21)]) while startscreen == True: - feld = change_block(feld,ascii.start_screen_text,[ty,int(tx/2-5)]) - prfeld(feld) + scene.set_block(ascii.start_screen_text,[ty,int(tx/2-5)]) + scene.print() sleep(0.2) - clear() + scene.clear() if key_space == True: while not key_space == False: startscreen = False - feld = viereck(feld,[ty,int(tx/2-4)],11,1," ") - prfeld(feld) + scene.viereck([ty,int(tx/2-4)],11,1," ") + scene.print() sleep(0.2) - clear() + scene.clear() if key_space == True: while not key_space == False: startscreen = False - feld = bg_char(feld," ") - feld = change_block(feld,ascii.cowsay,[int(ty/2)-2,int (tx/2)-12]) + scene.bg_char(" ") + scene.set_block(scene,ascii.cowsay,[int(ty/2)-2,int (tx/2)-12]) cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕" cowlistlength = len(cows) - cow = "#" cows[random.randint(0, cowlistlength - 1)] - clear() - #feld[ty][tx] ### 2zeichen kuhh mach probleme + cow = "#" #cows[random.randint(0, cowlistlength - 1)] + scene.clear() + #scene[ty][tx] ### 2zeichen kuhh mach probleme while running == True: wobl = "-" * (tx - wobble_pos - 5) wobr = "-" * wobble_pos wobbl = f"{wobr}{cow}{wobl}" - feld = change_block(feld," " * txhalb+"↓",[ty-1,0]) - feld = change_block(feld,f"[{wobbl}]",[ty,0]) - prfeld(feld) + scene.set_block(" " * txhalb+"↓",[ty-1,0]) + scene.set_block(f"[{wobbl}]",[ty,0]) + scene.print() if wobble_pos > txhalb: wobble_site = "left" else: @@ -95,57 +95,45 @@ if __name__ == "__main__" and running == True: wobble_way = "right" sleep(wobble_speed) - clear() + scene.clear() if key_space == True: break points_prozent = int((points/txhalb)*100) - clear() + scene.clear() for a in range(int(points*2)-2): - feld = change_block(feld,"-"*a+"🐄️",[0,0]) - feld = change_block(feld,str(points_prozent)+"%",[1,int(tx/2-2)]) - prfeld(feld) + scene.set_block("-"*a+cow,[0,0])#🐄️ + scene.set_block(str(points_prozent)+"%",[1,int(tx/2-2)]) + scene.print() sleep(0.01) - clear() - prfeld(feld) + scene.clear() + scene.print() + exit() -## 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 = tx-1 #termsize_xy[0] - 1 -#xsteps = 20#xmax -#ymax = ty #termsize_xy[1] -#ymin = 0 -#xmin = 0 -#startwinkel = 70 -#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=1, xstep=2) -# -#feld = bg_char(feld,"-") -# -## here we draw the cow -#for count in range(xmin, len(ergebnis), 2): -# xold, yold = x, y -# x, y = ergebnis[count], ergebnis[count + 1] -# change_block(feld,"@",[x, y]) -# sleep(schlafzeit) -# change_block(feld,"#",[xold, yold]) #☁️ -# prfeld(feld) -# print() -#sleep(2) -##sys.exit(home + curon) \ No newline at end of file + xsteps = int((tx+2)/2) #20#xmax + xmax = tx-1 #termsize_xy[0] - 1 + ymax = ty #termsize_xy[1] + ymin = 0 + xmin = 0 + startwinkel = 70#+180 + startgeschwindigkeit = 30 + starthoehe = 0#int(ty/2) + #### + ## needed for erasing old position + + ## Call the function, which calculates the coordinates) + ergebnis = berechneflugbahn(xmax, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe, gravitation=1, xstep=2) + # + ## here we draw the cow + xold = xmin + yold = ymin + x = xmin + y = xmin + for count in range(2, len(ergebnis), 2): + xold, yold = x, y + x, y = ergebnis[count], ergebnis[count + 1] + set_block(scene,"@",[x, y]) + sleep(0.1) + set_block(scene,"-",[xold, yold]) #☁️ + scene.print() \ No newline at end of file