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
|
first_run = True
|
||||||
|
|
||||||
# cowlength is 2, if cow is an UTF8-Icon, otherwise 1
|
# 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.
|
# 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)
|
y = (-(gravitation / (2 * startgeschwindigkeit**2 * cos(startwinkel) ** 2)) * x**2) + (tan(startwinkel) * x + starthoehe)
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -2,24 +2,34 @@
|
||||||
from os import get_terminal_size
|
from os import get_terminal_size
|
||||||
tx,ty = get_terminal_size().columns ,get_terminal_size().lines-2
|
tx,ty = get_terminal_size().columns ,get_terminal_size().lines-2
|
||||||
|
|
||||||
def genfeld():
|
class tengine():
|
||||||
return [[' ' for _ in range(tx)] for _ in range(ty+2)]
|
def __init__(self) -> None:
|
||||||
|
self.screen = [[' ' for _ in range(tx)] for _ in range(ty+2)]
|
||||||
|
|
||||||
def bg_char(feld, char=' '):
|
def print(self):
|
||||||
for a in range(len(feld)):
|
print(self.strscreen(),end="\r")
|
||||||
for b in range(len(feld[0])):
|
|
||||||
feld[a][b] = char
|
|
||||||
return feld
|
|
||||||
|
|
||||||
def strfeld(feld):
|
def bg_char(self, char=' '):
|
||||||
return '\n'.join([''.join(row) for row in feld]).lstrip('\n').rstrip('\n')
|
self.prfeld()
|
||||||
def prfeld(feld):
|
for a in range(len(self.screen)):
|
||||||
print(strfeld(feld),end="\r")
|
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):
|
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 set_char(self, character, position):
|
||||||
|
self.screen[position[0]][position[1]] = character
|
||||||
|
|
||||||
|
def set_block(self, block, position):
|
||||||
position = [position[0]+1,position[1]]
|
position = [position[0]+1,position[1]]
|
||||||
pposition = position
|
pposition = position
|
||||||
for zeichen in block:
|
for zeichen in block:
|
||||||
|
@ -27,26 +37,17 @@ def change_block(feld, block, position):
|
||||||
pposition = [pposition[0] + 1, position[1]]
|
pposition = [pposition[0] + 1, position[1]]
|
||||||
else:
|
else:
|
||||||
pposition = [pposition[0], pposition[1] + 1]
|
pposition = [pposition[0], pposition[1] + 1]
|
||||||
feld[pposition[0]][pposition[1]] = zeichen
|
self.screen[pposition[0]][pposition[1]] = zeichen
|
||||||
return feld
|
|
||||||
|
|
||||||
def clear():
|
def clear(self):
|
||||||
print('\033c', end='')
|
print('\033c', end='')
|
||||||
|
|
||||||
def draw_border(feld, border_char='+'):
|
def draw_border(self, border_char='+'):
|
||||||
for i in range(len(feld)):
|
for i in range(len(self.screen)):
|
||||||
feld[i][0] = feld[i][-1] = border_char
|
self.screen[i][0] = self.screen[i][-1] = border_char
|
||||||
for j in range(len(feld[0])):
|
for j in range(len(self.screen[0])):
|
||||||
feld[0][j] = feld[-1][j] = border_char
|
self.screen[0][j] = self.screen[-1][j] = border_char
|
||||||
global tx,ty
|
def viereck(self, start_pos, width, height, fill_char='#'):
|
||||||
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 i in range(height):
|
||||||
for j in range(width):
|
for j in range(width):
|
||||||
feld[start_pos[0]+1 + i][start_pos[1] + j] = fill_char
|
self.screen[start_pos[0]+1 + i][start_pos[1] + j] = fill_char
|
||||||
return feld
|
|
116
v2.py
116
v2.py
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
#import os
|
#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 pynput import keyboard
|
||||||
from time import sleep
|
from time import sleep
|
||||||
#from physics.parabelfunc import berechneflugbahn
|
from physics.parabelfunc import berechneflugbahn
|
||||||
import ascii
|
import ascii
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
@ -37,40 +37,40 @@ if not ty >= 11 :
|
||||||
print("please resize you teerminal over 11 lines")
|
print("please resize you teerminal over 11 lines")
|
||||||
|
|
||||||
if __name__ == "__main__" and running == True:
|
if __name__ == "__main__" and running == True:
|
||||||
feld = genfeld()
|
scene = tengine()
|
||||||
feld = change_block(feld,ascii.logo,[0,int(tx/2-21)])
|
scene.set_block(ascii.logo,[0,int(tx/2-21)])
|
||||||
|
|
||||||
while startscreen == True:
|
while startscreen == True:
|
||||||
feld = change_block(feld,ascii.start_screen_text,[ty,int(tx/2-5)])
|
scene.set_block(ascii.start_screen_text,[ty,int(tx/2-5)])
|
||||||
prfeld(feld)
|
scene.print()
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
clear()
|
scene.clear()
|
||||||
if key_space == True:
|
if key_space == True:
|
||||||
while not key_space == False:
|
while not key_space == False:
|
||||||
startscreen = False
|
startscreen = False
|
||||||
|
|
||||||
feld = viereck(feld,[ty,int(tx/2-4)],11,1," ")
|
scene.viereck([ty,int(tx/2-4)],11,1," ")
|
||||||
prfeld(feld)
|
scene.print()
|
||||||
sleep(0.2)
|
sleep(0.2)
|
||||||
clear()
|
scene.clear()
|
||||||
if key_space == True:
|
if key_space == True:
|
||||||
while not key_space == False:
|
while not key_space == False:
|
||||||
startscreen = False
|
startscreen = False
|
||||||
|
|
||||||
feld = bg_char(feld," ")
|
scene.bg_char(" ")
|
||||||
feld = change_block(feld,ascii.cowsay,[int(ty/2)-2,int (tx/2)-12])
|
scene.set_block(scene,ascii.cowsay,[int(ty/2)-2,int (tx/2)-12])
|
||||||
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
|
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
|
||||||
cowlistlength = len(cows)
|
cowlistlength = len(cows)
|
||||||
cow = "#" cows[random.randint(0, cowlistlength - 1)]
|
cow = "#" #cows[random.randint(0, cowlistlength - 1)]
|
||||||
clear()
|
scene.clear()
|
||||||
#feld[ty][tx] ### 2zeichen kuhh mach probleme
|
#scene[ty][tx] ### 2zeichen kuhh mach probleme
|
||||||
while running == True:
|
while running == True:
|
||||||
wobl = "-" * (tx - wobble_pos - 5)
|
wobl = "-" * (tx - wobble_pos - 5)
|
||||||
wobr = "-" * wobble_pos
|
wobr = "-" * wobble_pos
|
||||||
wobbl = f"{wobr}{cow}{wobl}"
|
wobbl = f"{wobr}{cow}{wobl}"
|
||||||
feld = change_block(feld," " * txhalb+"↓",[ty-1,0])
|
scene.set_block(" " * txhalb+"↓",[ty-1,0])
|
||||||
feld = change_block(feld,f"[{wobbl}]",[ty,0])
|
scene.set_block(f"[{wobbl}]",[ty,0])
|
||||||
prfeld(feld)
|
scene.print()
|
||||||
if wobble_pos > txhalb:
|
if wobble_pos > txhalb:
|
||||||
wobble_site = "left"
|
wobble_site = "left"
|
||||||
else:
|
else:
|
||||||
|
@ -95,57 +95,45 @@ if __name__ == "__main__" and running == True:
|
||||||
wobble_way = "right"
|
wobble_way = "right"
|
||||||
|
|
||||||
sleep(wobble_speed)
|
sleep(wobble_speed)
|
||||||
clear()
|
scene.clear()
|
||||||
|
|
||||||
if key_space == True:
|
if key_space == True:
|
||||||
break
|
break
|
||||||
points_prozent = int((points/txhalb)*100)
|
points_prozent = int((points/txhalb)*100)
|
||||||
clear()
|
scene.clear()
|
||||||
for a in range(int(points*2)-2):
|
for a in range(int(points*2)-2):
|
||||||
feld = change_block(feld,"-"*a+"🐄️",[0,0])
|
scene.set_block("-"*a+cow,[0,0])#🐄️
|
||||||
feld = change_block(feld,str(points_prozent)+"%",[1,int(tx/2-2)])
|
scene.set_block(str(points_prozent)+"%",[1,int(tx/2-2)])
|
||||||
prfeld(feld)
|
scene.print()
|
||||||
sleep(0.01)
|
sleep(0.01)
|
||||||
clear()
|
scene.clear()
|
||||||
prfeld(feld)
|
scene.print()
|
||||||
|
|
||||||
|
exit()
|
||||||
|
|
||||||
## Randomly choose a cow
|
xsteps = int((tx+2)/2) #20#xmax
|
||||||
#cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️ 🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
|
xmax = tx-1 #termsize_xy[0] - 1
|
||||||
#cowlistlength = len(cows)
|
ymax = ty #termsize_xy[1]
|
||||||
#cow = cows[random.randint(0, cowlistlength - 1)]
|
ymin = 0
|
||||||
## Needed: find our screensize. We are in textmode here
|
xmin = 0
|
||||||
##termsize_xy = os.get_terminal_size()
|
startwinkel = 70#+180
|
||||||
#### I m p o r t a n t p a r a m e t e r s ###
|
startgeschwindigkeit = 30
|
||||||
## X-Resolution of the display
|
starthoehe = 0#int(ty/2)
|
||||||
#xmax = tx-1 #termsize_xy[0] - 1
|
####
|
||||||
#xsteps = 20#xmax
|
## needed for erasing old position
|
||||||
#ymax = ty #termsize_xy[1]
|
|
||||||
#ymin = 0
|
## Call the function, which calculates the coordinates)
|
||||||
#xmin = 0
|
ergebnis = berechneflugbahn(xmax, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe, gravitation=1, xstep=2)
|
||||||
#startwinkel = 70
|
#
|
||||||
#startgeschwindigkeit = 60
|
## here we draw the cow
|
||||||
#starthoehe = 0
|
xold = xmin
|
||||||
#schlafzeit = 0.05
|
yold = ymin
|
||||||
####
|
x = xmin
|
||||||
## needed for erasing old position
|
y = xmin
|
||||||
#xold = xmin
|
for count in range(2, len(ergebnis), 2):
|
||||||
#yold = ymin
|
xold, yold = x, y
|
||||||
#x = xmin
|
x, y = ergebnis[count], ergebnis[count + 1]
|
||||||
#y = xmin
|
set_block(scene,"@",[x, y])
|
||||||
## Call the function, which calculates the coordinates)
|
sleep(0.1)
|
||||||
#ergebnis = berechneflugbahn(xmax, ymax, xsteps, startwinkel, startgeschwindigkeit, starthoehe, gravitation=1, xstep=2)
|
set_block(scene,"-",[xold, yold]) #☁️
|
||||||
#
|
scene.print()
|
||||||
#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)
|
|
Loading…
Reference in a new issue