Last active
April 12, 2022 19:58
-
-
Save Starbuck5/7cc985d99b85da5c975d5c649e00748b to your computer and use it in GitHub Desktop.
Simple mirror using pygame.camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import pygame.camera | |
pygame.init() | |
pygame.camera.init() | |
desired_size = (1280, 720) | |
cameras = pygame.camera.list_cameras() | |
cam = pygame.camera.Camera(cameras[0], desired_size) | |
cam.set_controls(hflip=True) | |
cam.start() | |
width, height = cam.get_size() | |
screen = pygame.display.set_mode((width, height)) | |
pygame.display.set_caption("Mirror") | |
clock = pygame.time.Clock() | |
running = True | |
while running: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
running = False | |
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: | |
running = False | |
if cam.query_image(): | |
screen.blit(cam.get_image(), (0,0)) | |
pygame.display.flip() | |
clock.tick(144) | |
cam.stop() | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment