engine umschmweißen
This commit is contained in:
parent
bc660afdbc
commit
d83e2f7232
5 changed files with 97 additions and 108 deletions
Binary file not shown.
|
@ -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)
|
||||
|
||||
|
|
Binary file not shown.
|
@ -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 change_char(feld, character, position):
|
||||
feld[position[0]][position[1]] = character
|
||||
|
||||
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 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 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 set_char(self, character, position):
|
||||
self.screen[position[0]][position[1]] = character
|
||||
|
||||
#def move_cursor(x, y):
|
||||
# print(f'\033[{y};{x}H', end='')
|
||||
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 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 clear(self):
|
||||
print('\033c', end='')
|
||||
|
||||
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
|
116
v2.py
116
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)
|
||||
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()
|
Loading…
Reference in a new issue