You can now low

This commit is contained in:
cubernetes 2023-08-11 04:50:33 +02:00
parent ba24bbdf9a
commit 4abb6cc7d5
3 changed files with 15 additions and 2 deletions

Binary file not shown.

12
game.py
View File

@ -75,7 +75,8 @@ def add_directional_triangle(
# TODO: Fix type issue # TODO: Fix type issue
side_len *= norm / 15 side_len *= norm / 15
stretch /= (norm/30) # stretch /= (norm/30)
triangle_height: float = side_len * (3**0.5) / 2 triangle_height: float = side_len * (3**0.5) / 2
half_base: float = side_len / 2 half_base: float = side_len / 2
@ -112,6 +113,8 @@ def main() -> int:
score: int = 0 score: int = 0
finger_x: int = -1 finger_x: int = -1
finger_y: int = -1 finger_y: int = -1
no_collect_ratio = 0
no_finger_ratio = 0
i: int = 0 i: int = 0
while True: while True:
@ -136,16 +139,21 @@ def main() -> int:
img42_y + rand_noise_y : img42_y + img42_side_len + rand_noise_y, img42_y + rand_noise_y : img42_y + img42_side_len + rand_noise_y,
img42_x + rand_noise_x : img42_x + img42_side_len + rand_noise_x, img42_x + rand_noise_x : img42_x + img42_side_len + rand_noise_x,
] = img42 ] = img42
no_collect_ratio = min(i, 200) / 200
finger_positions = list(get_finger_positions(frame, hands, add_landmarks=True)) finger_positions = list(get_finger_positions(frame, hands, add_landmarks=True))
if finger_positions == []: if finger_positions == []:
no_fingers += 1 no_fingers += 1
no_finger_ratio = min(no_fingers, 255) / 255
else: else:
no_fingers = 0 no_fingers = 0
if no_fingers > 200: if no_fingers > 255:
music.kill() music.kill()
return score return score
ratio = max(no_finger_ratio, no_collect_ratio)
frame = cv2.addWeighted(frame, 1 - ratio, np.ones(frame.shape, dtype=frame.dtype), ratio, 0)
for positions in finger_positions: for positions in finger_positions:
index_knuckle_1_pos: tuple[int, int] = (-1, -1) index_knuckle_1_pos: tuple[int, int] = (-1, -1)
for finger_id, finger_x, finger_y in positions: for finger_id, finger_x, finger_y in positions:

View File

@ -1,10 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
from time import sleep from time import sleep
from typing import NoReturn from typing import NoReturn
from utils import * from utils import *
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
def start_game() -> None: def start_game() -> None:
proc = Popen(['./start_game.sh']) proc = Popen(['./start_game.sh'])
proc.communicate() proc.communicate()