Hm, refactor necessary
This commit is contained in:
parent
14ef055eaa
commit
b0d21d30a3
30
game.py
30
game.py
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
|
from time import sleep
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import NoReturn, Generator
|
from typing import NoReturn, Generator
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
@ -120,7 +121,7 @@ def add_directional_triangle(
|
||||||
def get_finger_positions(
|
def get_finger_positions(
|
||||||
frame: np.ndarray,
|
frame: np.ndarray,
|
||||||
hands: mp.solutions.hands.Hands,
|
hands: mp.solutions.hands.Hands,
|
||||||
add_landmarks: bool,
|
add_landmarks: bool=False,
|
||||||
) -> Generator[list[tuple[int, int, int]], None, None]:
|
) -> Generator[list[tuple[int, int, int]], None, None]:
|
||||||
height, width = frame.shape[:2]
|
height, width = frame.shape[:2]
|
||||||
|
|
||||||
|
@ -148,9 +149,24 @@ def show_frame(frame: np.ndarray, to_stdout: bool=False) -> None:
|
||||||
def collect_sfx() -> None:
|
def collect_sfx() -> None:
|
||||||
Popen(['paplay', './assets/sfx/collect.mp3'])
|
Popen(['paplay', './assets/sfx/collect.mp3'])
|
||||||
|
|
||||||
def main() -> NoReturn:
|
def start_sfx() -> None:
|
||||||
Popen(['paplay', './assets/sfx/start.mp3'])
|
Popen(['paplay', './assets/sfx/start.mp3'])
|
||||||
|
|
||||||
|
def show_matrix(term_dev: str) -> None:
|
||||||
|
Popen(['sh', '-c', '2>/dev/null tmatrix 1>"' + term_dev + '"'])
|
||||||
|
|
||||||
|
def found_hands() -> bool:
|
||||||
|
capture: VideoCapture = cv2.VideoCapture(0)
|
||||||
|
hands = mp_hands.Hands(max_num_hands=1)
|
||||||
|
success, frame = capture.read()
|
||||||
|
if not success:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return list(get_finger_positions(frame, hands)) != []
|
||||||
|
|
||||||
|
def game_loop() -> int:
|
||||||
|
start_sfx()
|
||||||
|
|
||||||
capture: VideoCapture = cv2.VideoCapture(0)
|
capture: VideoCapture = cv2.VideoCapture(0)
|
||||||
hands = mp_hands.Hands(max_num_hands=2)
|
hands = mp_hands.Hands(max_num_hands=2)
|
||||||
collected_42 = True
|
collected_42 = True
|
||||||
|
@ -198,5 +214,15 @@ def main() -> NoReturn:
|
||||||
show_frame(frame, to_stdout=(not sys.stdout.isatty()))
|
show_frame(frame, to_stdout=(not sys.stdout.isatty()))
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
def main() -> NoReturn:
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print(f'Usage: {sys.argv[0]} TERMINAL_DEVICE')
|
||||||
|
sys.exit(1)
|
||||||
|
show_matrix(sys.argv[1])
|
||||||
|
while True:
|
||||||
|
if found_hands():
|
||||||
|
game_loop()
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -4,18 +4,11 @@ import sys
|
||||||
from typing import NoReturn
|
from typing import NoReturn
|
||||||
|
|
||||||
def main() -> NoReturn:
|
def main() -> NoReturn:
|
||||||
x = 0
|
|
||||||
y = 0
|
|
||||||
while True:
|
while True:
|
||||||
chunk = sys.stdin.buffer.read(100)
|
chunk = sys.stdin.buffer.read(100)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
continue
|
continue
|
||||||
nls = chunk.count(b'\n')
|
modified_chunk = chunk.replace(b'X', b'.')
|
||||||
if nls != 0:
|
|
||||||
open('/dev/pts/1', 'w').write(
|
|
||||||
f'{nls}'
|
|
||||||
)
|
|
||||||
modified_chunk = chunk
|
|
||||||
sys.stdout.buffer.write(modified_chunk)
|
sys.stdout.buffer.write(modified_chunk)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
# st -f 'SauceCodePro Nerd Font Mono:size=10' -e sh -c '{ ./game.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx265 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
|
# st -f 'SauceCodePro Nerd Font Mono:size=10' -e sh -c '{ ./game.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx265 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=caca --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
|
||||||
# st -f 'SauceCodePro Nerd Font Mono:size=10' -e sh -c '{ ./game.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx264 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=tct --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
|
# st -f 'SauceCodePro Nerd Font Mono:size=10' -e sh -c '{ ./game.py | 2>/dev/null ffmpeg -y -f rawvideo -s 640x480 -pix_fmt bgr24 -i - -map 0:V:0 -filter:v "format=gray,hflip" -c:v libx264 -preset ultrafast -tune zerolatency -crf 30 -f nut - | TERM=xterm-mono CACA_DRIVER=ncurses DISPLAY= mpv --really-quiet --no-cache --no-config --vo=tct --untimed --profile=low-latency - || { echo Error 1>&2; read X; }; }'
|
||||||
|
|
||||||
export TERM_FONT='SauceCodePro Nerd Font Mono'
|
TERM_FONT='SauceCodePro Nerd Font Mono'
|
||||||
export TERM_FONT_SIZE='10'
|
TERM_FONT_SIZE='10'
|
||||||
export OUT_TERM='xterm-mono'
|
OUT_TERM='xterm-mono'
|
||||||
|
TERM_DEV="$(tty)"
|
||||||
xterm \
|
xterm \
|
||||||
-bg black \
|
-bg black \
|
||||||
-fg white \
|
-fg white \
|
||||||
|
@ -13,7 +14,7 @@ xterm \
|
||||||
-fa "${TERM_FONT}" \
|
-fa "${TERM_FONT}" \
|
||||||
-fs "${TERM_FONT_SIZE}" \
|
-fs "${TERM_FONT_SIZE}" \
|
||||||
-e '{
|
-e '{
|
||||||
./game.py |
|
./game.py "'"${TERM_DEV}"'" |
|
||||||
2>/dev/null ffmpeg -y \
|
2>/dev/null ffmpeg -y \
|
||||||
-f rawvideo \
|
-f rawvideo \
|
||||||
-s 640x480 \
|
-s 640x480 \
|
||||||
|
|
Loading…
Reference in New Issue