Skripty

Audio player #

import pygame

# Initialize Pygame and its mixer
pygame.init()
pygame.mixer.init()

# Load the sound file
sound_file = 'path/to/your/soundfile.wav'  # Replace with the path to your sound file
sound = pygame.mixer.Sound(sound_file)

# Play the sound
sound.play()

# Keep the program running until the sound is done playing
while pygame.mixer.get_busy():
    pygame.time.delay(100)

Panacik #

#!/usr/bin/env python3
#
# Panacik
#
#
import pythonosc.osc_server
import pythonosc.dispatcher
import math
import numpy as np


# toto ma kazdy ine
ip = "10.0.1.199"
port = 5050

dlzka_riadku = 150

def panacik(znak, pozicia):
    riadok = " " * dlzka_riadku
    novy = riadok[: (pozicia - 1)] + znak + riadok[pozicia:]
    return novy


def nakresli(addr, *args):
    val = np.interp(args[0], (80, 300), (0, dlzka_riadku))
    if not math.isnan(val):
        pozicia_panacika = int(val)
        print(panacik("o", pozicia_panacika))


# vytvorim dispecera
disp = pythonosc.dispatcher.Dispatcher()

# default co ma robit ked nieco pride
# disp.set_default_handler(print)
disp.map("/orientation/alpha", nakresli)

# server
server = pythonosc.osc_server.ThreadingOSCUDPServer((ip, port), disp)
server.serve_forever()

Vypisovatko #

import pythonosc.osc_server
import pythonosc.dispatcher

# toto ma kazdy ine
ip = "192.168.10.32"
port = 5050


def center(znak, pocetznakov, dlzka_riadku):
    dlzka_okraja = (dlzka_riadku - pocetznakov) // 2
    okraj = " " * dlzka_okraja
    obsah = znak * pocetznakov
    riadok = okraj + obsah + okraj
    return riadok


def mega(addr, *args):
    # print(addr)
    data = int(args[0])
    print(center("0", data, 500))


# vytvorim dispecera
disp = pythonosc.dispatcher.Dispatcher()
# default co ma robit ked nieco pride
# disp.set_default_handler(print)
disp.map("/orientation/alpha", mega)

# server
server = pythonosc.osc_server.ThreadingOSCUDPServer((ip, port), disp)
server.serve_forever()

aplikacie #

https://apps.apple.com/us/app/data-osc/id6447833736 https://apkcombo.com/oschook/com.hollyhook.oscHook/

Snake #

import pygame
import sys
import random
import time

# Initialize Pygame
pygame.init()

# Get the screen dimensions
screen_info = pygame.display.Info()
WIDTH, HEIGHT = screen_info.current_w, screen_info.current_h

# Set the GRID_SIZE, FPS, and SPARKLE_DURATION
GRID_SIZE = 30
FPS = 10
SPARKLE_DURATION = FPS  # Number of frames for the sparkle to last (1 second)
SPARKLE_TIMER = 0  # Time (in seconds) to activate the sparkle effect

# Snake class
class Snake:
    def __init__(self):
        self.length = 1
        self.positions = [(WIDTH // 2, HEIGHT // 2)]
        self.direction = (0, 0)
        self.head_image = pygame.image.load("C:/Users/alexa/Desktop/skola/snake_head.jpg")
        self.head_image = pygame.transform.scale(self.head_image, (GRID_SIZE * 3, GRID_SIZE * 3))

    def get_head_position(self):
        return self.positions[0]

    def update(self):
        cur = self.get_head_position()
        x, y = self.direction
        new = (((cur[0] + (x * GRID_SIZE)) % WIDTH), (cur[1] + (y * GRID_SIZE)) % HEIGHT)
        if len(self.positions) > 2 and new in self.positions[2:]:
            self.reset()
        else:
            self.positions.insert(0, new)
            if len(self.positions) > self.length:
                self.positions.pop()

    def reset(self):
        self.length = 1
        self.positions = [(WIDTH // 2, HEIGHT // 2)]
        self.direction = (0, 0)

    def render(self, surface):
        # Render the rest of the body
        for p in self.positions[1:]:
            surface.blit(self.head_image, (p[0], p[1]))

        # Render the head separately
        surface.blit(self.head_image, (self.positions[0][0], self.positions[0][1]))

# Food class
class Food:
    def __init__(self):
        self.position = (0, 0)
        self.image = pygame.image.load("C:/Users/alexa/Desktop/skola/food.jpg")
        self.image = pygame.transform.scale(self.image, (GRID_SIZE * 3, GRID_SIZE * 3))
        self.rect = self.image.get_rect()  # Get the rect object for collision detection
        self.randomize_position()
        self.sparkle_counter = 0  # Counter for sparkle animation

        # Load Grindr message sound (Replace "path_to_grindr_sound.wav" with the actual path and name of your sound file)
        self.eat_sound = pygame.mixer.Sound(r"C:\Users\alexa\Desktop\skola\grindr.mp3")

    def randomize_position(self):
        self.position = (random.randint(0, (WIDTH // GRID_SIZE) - 1) * GRID_SIZE,
                         random.randint(0, (HEIGHT // GRID_SIZE) - 1) * GRID_SIZE)
        self.rect.topleft = self.position  # Update the rect position
        self.sparkle_counter = SPARKLE_DURATION  # Reset the sparkle counter

    def render(self, surface):
        surface.blit(self.image, self.position)

        # Render sparkle animation (falling stars)
        if self.sparkle_counter > 0:
            for _ in range(10):  # Render 10 stars per frame
                star_size = random.randint(15, 30)
                star_position = (random.randint(0, WIDTH - star_size), random.randint(0, HEIGHT - star_size))
                pygame.draw.rect(surface, (255, 215, 0), (star_position[0], star_position[1], star_size, star_size))
            self.sparkle_counter -= 1  # Decrease the sparkle counter

    def play_eat_sound(self):
        self.eat_sound.play()

# Scoreboard class
class Scoreboard:
    def __init__(self):
        # Use a digital clock font if available, otherwise, use the default font
        try:
            self.font = pygame.font.Font(pygame.font.match_font('digital-7'), 200)
        except pygame.error:
            self.font = pygame.font.Font(None, 150)  # Use the default font with a size of 150
        self.color = (255, 0, 0, 140)  # Red color with 55% opacity
        self.position = (WIDTH // 2, HEIGHT // 10)  # Centered at the top
        self.text = ""

    def render(self, surface, score):
        self.text = str(score)
        text_render = self.font.render(self.text, True, self.color)
        text_rect = text_render.get_rect(center=self.position)
        surface.blit(text_render, text_rect)

# Main function
def main():
    global SPARKLE_TIMER  # Declare SPARKLE_TIMER as a global variable

    # Create a fullscreen display
    screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

    # Get the new screen dimensions
    WIDTH, HEIGHT = screen.get_size()

    background_image = pygame.image.load("C:/Users/alexa/Desktop/skola/bordel.jpg")
    background_image = pygame.transform.scale(background_image, (WIDTH, HEIGHT))

    surface = pygame.Surface(screen.get_size())
    surface = surface.convert()

    snake = Snake()
    food = Food()
    scoreboard = Scoreboard()

    clock = pygame.time.Clock()

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    snake.direction = (0, -1)
                elif event.key == pygame.K_DOWN:
                    snake.direction = (0, 1)
                elif event.key == pygame.K_LEFT:
                    snake.direction = (-1, 0)
                elif event.key == pygame.K_RIGHT:
                    snake.direction = (1, 0)
                elif event.key == pygame.K_KP5 or (event.key == pygame.K_5 and pygame.key.get_mods() & pygame.KMOD_SHIFT):
                    pygame.quit()
                    sys.exit()

        snake.update()

        # Check for collision using rect objects
        if snake.get_head_position()[0] in range(food.rect.left, food.rect.right) and \
           snake.get_head_position()[1] in range(food.rect.top, food.rect.bottom):
            snake.length += 1
            food.randomize_position()
            food.play_eat_sound()  # Play the Grindr message sound
            SPARKLE_TIMER = FPS  # Activate the sparkle effect for 1 second

        # Draw background image
        surface.blit(background_image, (0, 0))

        # Update sparkle animation
        if SPARKLE_TIMER > 0:
            food.render(surface)
        else:
            SPARKLE_TIMER = 0  # Ensure SPARKLE_TIMER remains 0 when not in use
            food.render(surface)

        snake.render(surface)
        food.render(surface)
        scoreboard.render(surface, snake.length)  # Render the scoreboard
        screen.blit(surface, (0, 0))
        pygame.display.update()
        clock.tick(FPS)

if __name__ == "__main__":
    main()

Gesta #

:EXPORT_HUGO_SECTION: docs/interaktivita_w_23/skripty :EXPORT_FILE_NAME: gesta :EXPORT_HUGO_MENU_OVERRIDE: :weight 1

https://www.geeksforgeeks.org/face-and-hand-landmarks-detection-using-python-mediapipe-opencv/


# Import Libraries
import cv2
import time
import mediapipe as mp


# Grabbing the Holistic Model from Mediapipe and
# Initializing the Model
mp_holistic = mp.solutions.holistic
holistic_model = mp_holistic.Holistic(
    min_detection_confidence=0.5, min_tracking_confidence=0.5
)

# Initializing the drawing utils for drawing the facial landmarks on image
mp_drawing = mp.solutions.drawing_utils
# (0) in VideoCapture is used to connect to your computer's default camera
capture = cv2.VideoCapture(0)

# Initializing current time and precious time for calculating the FPS
previousTime = 0
currentTime = 0

while capture.isOpened():
    # capture frame by frame
    ret, frame = capture.read()

    # resizing the frame for better view
    frame = cv2.resize(frame, (800, 600))

    # Converting the from BGR to RGB
    image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

    # Making predictions using holistic model
    # To improve performance, optionally mark the image as not writeable to
    # pass by reference.
    image.flags.writeable = False
    results = holistic_model.process(image)
    image.flags.writeable = True

    # Converting back the RGB image to BGR
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

    # Drawing the Facial Landmarks
    mp_drawing.draw_landmarks(
        image,
        results.face_landmarks,
        mp_holistic.FACEMESH_CONTOURS,
        mp_drawing.DrawingSpec(color=(255, 0, 255), thickness=1, circle_radius=1),
        mp_drawing.DrawingSpec(color=(0, 255, 255), thickness=1, circle_radius=1),
    )

    # Drawing Right hand Land Marks
    mp_drawing.draw_landmarks(
        image, results.right_hand_landmarks, mp_holistic.HAND_CONNECTIONS
    )

    # Drawing Left hand Land Marks
    mp_drawing.draw_landmarks(
        image, results.left_hand_landmarks, mp_holistic.HAND_CONNECTIONS
    )

    # Calculating the FPS
    currentTime = time.time()
    fps = 1 / (currentTime - previousTime)
    previousTime = currentTime

    # Displaying FPS on the image
    cv2.putText(
        image,
        str(int(fps)) + " FPS",
        (10, 70),
        cv2.FONT_HERSHEY_COMPLEX,
        1,
        (0, 255, 0),
        2,
    )

    # Display the resulting image
    cv2.imshow("Facial and Hand Landmarks", image)

    # Enter key 'q' to break the loop
    if cv2.waitKey(5) & 0xFF == ord("q"):
        break

# When all the process is done
# Release the capture and destroy all windows
capture.release()
cv2.destroyAllWindows()
# Code to access landmarks
for landmark in mp_holistic.HandLandmark:
    print(landmark, landmark.value)

print(mp_holistic.HandLandmark.WRIST.value)