diff --git a/game.py b/game.py index 2f9a4d1..4f0a460 100755 --- a/game.py +++ b/game.py @@ -2,6 +2,7 @@ import sys import random +from time import sleep from enum import Enum from typing import NoReturn, Generator from types import ModuleType @@ -120,7 +121,7 @@ def add_directional_triangle( def get_finger_positions( frame: np.ndarray, hands: mp.solutions.hands.Hands, - add_landmarks: bool, + add_landmarks: bool=False, ) -> Generator[list[tuple[int, int, int]], None, None]: height, width = frame.shape[:2] @@ -148,9 +149,24 @@ def show_frame(frame: np.ndarray, to_stdout: bool=False) -> None: def collect_sfx() -> None: Popen(['paplay', './assets/sfx/collect.mp3']) -def main() -> NoReturn: +def start_sfx() -> None: 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) hands = mp_hands.Hands(max_num_hands=2) collected_42 = True @@ -198,5 +214,15 @@ def main() -> NoReturn: show_frame(frame, to_stdout=(not sys.stdout.isatty())) 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__': main() diff --git a/pipe_intercept.py b/pipe_intercept.py index 6dd5cdc..5de2b71 100755 --- a/pipe_intercept.py +++ b/pipe_intercept.py @@ -4,18 +4,11 @@ import sys from typing import NoReturn def main() -> NoReturn: - x = 0 - y = 0 while True: chunk = sys.stdin.buffer.read(100) if not chunk: continue - nls = chunk.count(b'\n') - if nls != 0: - open('/dev/pts/1', 'w').write( - f'{nls}' - ) - modified_chunk = chunk + modified_chunk = chunk.replace(b'X', b'.') sys.stdout.buffer.write(modified_chunk) sys.stdout.flush() diff --git a/start_game.sh b/start_game.sh index 09def37..8097638 100755 --- a/start_game.sh +++ b/start_game.sh @@ -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 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' -export TERM_FONT_SIZE='10' -export OUT_TERM='xterm-mono' +TERM_FONT='SauceCodePro Nerd Font Mono' +TERM_FONT_SIZE='10' +OUT_TERM='xterm-mono' +TERM_DEV="$(tty)" xterm \ -bg black \ -fg white \ @@ -13,7 +14,7 @@ xterm \ -fa "${TERM_FONT}" \ -fs "${TERM_FONT_SIZE}" \ -e '{ - ./game.py | + ./game.py "'"${TERM_DEV}"'" | 2>/dev/null ffmpeg -y \ -f rawvideo \ -s 640x480 \