great update # aber komme mit wuffels parrable funktion nicht klar

This commit is contained in:
Michael S. 2024-01-13 19:55:47 +01:00
parent e49d31babc
commit d4aa1c12bb
16 changed files with 542 additions and 74 deletions

Binary file not shown.

Binary file not shown.

61
physics/kreis.py Normal file
View file

@ -0,0 +1,61 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys, termios, tty, time, random
from math import sin, cos, sqrt
from time import sleep
# Randomly choose a cow
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
cowslength = len(cows)
cow = cows[random.randint(0, cowslength - 1)]
# cow = "🐄"
# cow = "*"
if cow.isascii():
charlength = 1
else:
charlength = 2
# Needed: find our screensize
termsize_xy = os.get_terminal_size()
# maximum and medium of points in a row
xmax = termsize_xy[0] - 1
xmitte = xmax / 2
# maximum and medium of points in a column
ymax = termsize_xy[1]
ymitte = ymax / 2
# CTRL and ESC-codes for the used outputdevice. Probably a terminal.
clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h"
# pi is not defined by default. Noone has a display with 31416 Pixels in a row. U know better? Enhance it.
pi = 3.1416
# This is for convenience, if you are thinking in degrees. It must not be recalculated every loop.
deg2rad = pi / 180
# position cursor at x,y - where x=0 y=0 is the left lower corner like in mathematical diagrams
# some scales, we need. Those UTF8Cows are 2 chars wide and need more space. So we have to scale one Axis
radius = ymitte - 2
xradius = ymitte * charlength - 1
# Position the curser at x,y. Yes, we start with x, print does not, you are looking right. Leave it this way!
def curpos(x, y):
print("\033[%d;%dH" % (ymax - y, x), end="", flush=True)
print(clear, curoff)
# Draw a circle in maximum 360 Steps, one for for every degree
for winkel in range(0, 359):
x = sin(winkel * deg2rad) * xradius + xmitte
y = cos(winkel * deg2rad) * radius + ymitte
curpos(x, y)
print(cow, end="")
time.sleep(0.01)
curpos(1, 1)
sys.exit(curon + "Schulz nun.")

128
physics/parabelfunc.py Normal file
View file

@ -0,0 +1,128 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys, random #,termios, tty, time,
from math import sin, cos, tan, sqrt
from time import sleep
# pi is not defined by default
pi = 3.1416
deg2rad = pi / 180
########################################################################################
def berechneflugbahn(xmax, ymax, steps, startwinkel, startgeschwindigkeit, xmin=0, ymin=0, starthoehe=0, gravitation=9.81, xstep=1):
x = 0
y = x**2
# in scala the resulting coordinates will be returned
scala = []
startwinkel = startwinkel * deg2rad
# Calculate time of flight, actually not used
flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation
# Calculate maximum height
hoehe = 0.5 * gravitation * flugdauer**2 + starthoehe
# calculate length of flight, actually not used
wurfweite = (
startgeschwindigkeit
* cos(startwinkel)
* (startgeschwindigkeit * sin(startwinkel) + sqrt(startgeschwindigkeit**2 * sin(startwinkel) ** 2 + 2 * gravitation * starthoehe))
) / gravitation
first_run = True
# cowlength is 2, if cow is an UTF8-Icon, otherwise 1
for x in range(xmin, steps - 1, xstep):
# 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)
# Ensure, that nothing has to be drawn outside the viewport
if x >= xmax:
x = xmax
if y >= ymax:
y = ymax
elif y <= ymin:
y = ymin
# Stash away the coordinates into scala, which will be returned
scala += [x, int((y * 100 + 50) / 100)]
if y == ymin and not first_run:
break
first_run = False
return scala
#############################################################################################
# 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"
g_erde = 9.81 # gravitation examples
mond = 1.6
jupiter = 24
# set position of cursor
def curpos(x, y):
print("\033[%d;%dH" % (ymax - y, x), end="", flush=True)
if __name__ == "__main__":
# 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 = termsize_xy[0] - 1
xsteps = xmax * 2
ymax = termsize_xy[1]
ymin = 0
xmin = 0
startwinkel = 34
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=g_erde, xstep=2)
print(curoff)
# 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="")
sleep(schlafzeit)
curpos(xold, yold)
print("☁️ ", end="")
sleep(2)
sys.exit(home + curon)

128
physics/parabeltest.py Normal file
View file

@ -0,0 +1,128 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os, sys, termios, tty, time, random
from math import sin, cos, tan, sqrt
from time import sleep
# Randomly choose a cow
cows = "🐵🐒🦍🦧🐕🐯🦝🐩🐅🐴🐎🦄🦌🐗🐂🐃🐄🐪🐫🦙🦒🐹🦘🦡🐧🕊️🦅🦆🦉🐍🦎🐊🦜🦚🦩🐲🐉🦕"
cowlistlength = len(cows)
cow = cows[random.randint(0, cowlistlength - 1)]
cowlength = len(cow)
# Needed: find our screensize
termsize_xy = os.get_terminal_size()
xmax = termsize_xy[0] - 1
ymax = termsize_xy[1]
ymin = 0
xmin = 0
xold = xmin
# pi is not defined by default
pi = 3.1416
deg2rad = pi / 180
# position cursor at x,y - where x=0 y=0 is the left lower corner like in mathematical diagrams
def curpos(x, y):
print("\033[%d;%dH" % (ymax - y, x), end="", flush=True)
outputfile = open("cowyeetflugbahn.txt", "w")
# CTRL and ESC-codes for the used outputdevice. Probably a terminal.
clear, home, curoff, curon = "'\x1b[2J\x1b[H", "\x1b[H", "\x1b[?25l", "\x1b[?25h"
# some scales, we need
# not everything has to be recomputed in loops.
xsteps = xmax
x = 0
y = x**2
erde = 9.81
mond = 1.6
jupiter = 24
gravitation = erde
# in scala the resulting coordinates will be returned
scala = []
# used, if input is disabled
starthoehe = 0
startwinkel = 26 * deg2rad
startgeschwindigkeit = 36
loeschen = "y"
bla = input("Parameter editieren (y) oder Vorgabe nutzen?")
if bla == "y":
# Be a friendly host, lets have a talk.
# comment out to speed up testing
starthoehe = float(input("Starthöhe in Metern, empf: 0-20: "))
startwinkel = float(input("Startwinkel 0° - 90°: ")) * deg2rad
startgeschwindigkeit = float(input("Startgeschwindigkeit Meter (zb 20) pro Sekunde: "))
loeschen = input("Kuh löschen? (y/n)")
####
# Calculate time of flight
flugdauer = startgeschwindigkeit * sin(startwinkel) / gravitation
schlafdauer = flugdauer / xmax
# Calculate maximum height
hoehe = 0.5 * gravitation * flugdauer**2 + starthoehe
# calculate length of flight
wurfweite = (
startgeschwindigkeit
* cos(startwinkel)
* (startgeschwindigkeit * sin(startwinkel) + sqrt(startgeschwindigkeit**2 * sin(startwinkel) ** 2 + 2 * gravitation * starthoehe))
) / gravitation
# init screen and wait for userinput
print(clear, curoff)
print(
"xteps: ",
xsteps,
"\nwurfweite: ",
wurfweite,
"\nstartwinkel: ",
startwinkel / deg2rad,
"\nstartgeschwindigkeit: ",
startgeschwindigkeit,
"\nstarthoehe: ",
starthoehe,
"\nhoehe: ",
hoehe,
"\nschlafdauer: ",
schlafdauer,
)
bla = input("CR please:")
# position cursor down left corner
curpos(1, ymax)
# 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)
time.sleep(schlafdauer)
# Ensure, that nothing has to be drawn outside the viewport
if y < ymax and y > ymin:
curpos(x, y)
print(cow, end="")
# Stash awa the coordinates into scala, which will be returned
scala += [x, int(y * 10 + 5) / 10]
if loeschen == "y":
curpos(xold, yold)
print(" ", end="")
else:
scala += [x, 0]
xold = x
curpos(0, 0)
outputfile.write(str(scala))
sys.exit(curon + "Moooooooooooo.")

2
tengine/README.md Normal file
View file

@ -0,0 +1,2 @@
# A little Text Engine for Cowyeet

Binary file not shown.

Binary file not shown.

50
tengine/main.py Normal file
View file

@ -0,0 +1,50 @@
#!/bin/python3
from os import get_terminal_size
tx,ty = get_terminal_size().columns ,get_terminal_size().lines
def genfeld():
return [[' ' for _ in range(tx)] for _ in range(ty)]
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 strfeld(feld):
return '\n'.join([''.join(row) for row in feld])
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 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] + i][start_pos[1] + j] = fill_char
return feld

14
tengine/test.py Normal file
View file

@ -0,0 +1,14 @@
import forgejo.cowyeet_terminal.tengine.main as main
feld = main.genfeld()
block = "halli\nhallo\nfurz"
block2 = """halli
hallouuuuuuuuuuuuu
furz"""
feld = main.bg_char(feld,"#")
#feld = tengine.draw_border(feld)
feld = main.change_block(feld,block2,[2,2])
#feld = tengine.viereck(feld,[1,1],4,4,"-")
print(main.strfeld(feld))
#tengine.clear_screen()

View file

@ -1,42 +0,0 @@
from os import get_terminal_size
tx = get_terminal_size().columns
ty = get_terminal_size().lines
def genfeld():
feld = [[' ' for _ in range(tx)] for _ in range(ty)]
return feld
def bg_char(feld,char=str):
test = 0
for a in range(len(feld)):
for b in range(len(feld[0])):
feld[a][b] = test
test = char
return feld
def strfeld(feld):
back = ""
for a in feld:
for b in a:
back += str(b)
back += "\n"
return back
def change_char(feld,character=str,position=list):
feld[position[0]][position[1]] = character
def change_block(feld,string=str,position=list):
a = ""
block_len = 0
for a in string:
if a == "\n":
break
else:
block_len += 1
print(block_len)
for zeichen in string:
position[0] += 1
if position[0]== block_len-1:
position[0] = 0
feld[position[0]][position[1]] = zeichen
return feld

View file

@ -1,11 +0,0 @@
import tengine
feld = tengine.genfeld()
block = "halli\nhallo\nfurz"
block2 = """halli
hallo
furz"""
feld = tengine.bg_char(feld,"#")
feld = tengine.change_block(feld,block2,[3,3])
print(tengine.strfeld(feld))

50
v1.py
View file

@ -1,14 +1,15 @@
#!/usr/bin/python3
import os
from forgejo.cowyeet_terminal.tengine.main import ty,tx,clear
from pynput import keyboard
from time import sleep
def clear():
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
#def clear():
# if os.name == "nt":
# os.system("cls")
# else:
# os.system("clear")
def on_press(key):
@ -28,11 +29,11 @@ listener = keyboard.Listener(on_press=on_press, on_release=on_release)
listener.start()
tx, ty = os.get_terminal_size().columns, os.get_terminal_size().lines
txhalb = int(tx / 2)
txhalb = int(tx / 2)-2
wobble_speed = 0.01
wobble_pos = 0
wobble_way = "right"
points = 0
running = True
while running == True:
wobl = "-" * (tx - wobble_pos - 5)
@ -41,13 +42,29 @@ while running == True:
print(" " * txhalb, "")
print(f"[{wobbl}]")
print(wobble_pos)
print(points)
print(tx)
print(txhalb)
if wobble_pos > txhalb:
wobble_site = "left"
else:
wobble_site = "right"
if wobble_way == "right":
wobble_pos += 1
if wobble_site == "right":
points += 1
else:
points -= 1
else:
wobble_pos -= 1
if wobble_site == "right":
points -= 1
else:
points += 1
if wobble_pos >= tx - 1:
if wobble_pos >= tx - 4:
wobble_way = "left"
elif wobble_pos == 0:
wobble_way = "right"
@ -58,18 +75,11 @@ while running == True:
if running == "finito":
exit()
if wobble_pos > txhalb:
wobble_site = "left"
else:
wobble_site = "right"
#tx halb = max points #in ausgerechneten bruch und an in bruch mit nenner 100 ergibt zähler mit punktewert
if wobble_site == "right":
points = wobble_pos
else:
points = tx - wobble_pos
point_quote = points - tx / 100
for a in range(points * 2):
for a in range(int(points*2)):
print("-" * a + "🐄️", end="\r")
sleep(0.01)
print("\n", point_quote, "%")
points = int((points/txhalb)*100)
print("\n", points, "%")

128
v2.py Normal file
View file

@ -0,0 +1,128 @@
#!/usr/bin/python3
import os
from tengine.main import *#ty,tx,clear,genfeld,strfeld,change_char,bg_char
from pynput import keyboard
from time import sleep
from physics.parabelfunc import berechneflugbahn
import random
#def clear():
# if os.name == "nt":
# os.system("cls")
# else:
# os.system("clear")
def on_press(key):
global running
if key == keyboard.Key.space:
running = False
def on_release(key):
global running
if key == keyboard.Key.esc:
# Stop listener
running = "finito"
listener = keyboard.Listener(on_press=on_press, on_release=on_release)
listener.start()
txhalb = int(tx / 2)-2
wobble_speed = 0.01
wobble_pos = 0
wobble_way = "right"
points = 0
running = True
while running == True:
wobl = "-" * (tx - wobble_pos - 5)
wobr = "-" * wobble_pos
wobbl = f"{wobr}🐄️{wobl}"
print(" " * txhalb, "")
print(f"[{wobbl}]")
print(wobble_pos)
print(points)
print(tx)
print(txhalb)
if wobble_pos > txhalb:
wobble_site = "left"
else:
wobble_site = "right"
if wobble_way == "right":
wobble_pos += 1
if wobble_site == "right":
points += 1
else:
points -= 1
else:
wobble_pos -= 1
if wobble_site == "right":
points -= 1
else:
points += 1
if wobble_pos >= tx - 4:
wobble_way = "left"
elif wobble_pos == 0:
wobble_way = "right"
sleep(wobble_speed)
clear()
if running == "finito":
exit()
#tx halb = max points #in ausgerechneten bruch und an in bruch mit nenner 100 ergibt zähler mit punktewert
for a in range(int(points*2)):
print("-" * a + "🐄️", end="\r")
sleep(0.01)
points = int((points/txhalb)*100)
print("\n", points, "%")
feld = genfeld()
# 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]) #☁️
print(strfeld(feld))
print()
sleep(2)
#sys.exit(home + curon)