Skip to content

Instantly share code, notes, and snippets.

View Starbuck5's full-sized avatar

Charlie Hayden Starbuck5

View GitHub Profile
@Starbuck5
Starbuck5 / mirror.py
Last active April 12, 2022 19:58
Simple mirror using pygame.camera
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)
@Starbuck5
Starbuck5 / ascii_video_player.py
Created April 10, 2022 10:03
ASCII Video Player
import cv2
import pygame
import numpy
import functools
# WHAT IS THIS?
# This script is a simple ascii video player made in Python / pygame
# It allows you to drop in videos, or to use the webcam
pygame.init()
@Starbuck5
Starbuck5 / pong.py
Created April 10, 2022 08:42
Python/pygame pong in 1 line
while (locals().get("f") or [globals().update(p=__import__("pygame")), p.init(), globals().update(w=p.display.set_mode((800,600))), globals().update(r=[p.Rect(c) for c in [(0, 0, 20, 60), (780, 0, 20, 60), (390, 290, 20, 20)]]), globals().update(b=[5, 5]), locals().update(f=1)]) and [not p.QUIT in [event.type for event in p.event.get()], p.time.wait(10), w.fill(0), [[p.draw.rect, p.draw.ellipse][rx == r[2]](w, "white", rx) for rx in r], p.display.flip(), [r[0].move_ip(0, (p.key.get_pressed()[p.K_s] - p.key.get_pressed()[p.K_w]) * 5), r[1].move_ip(0, (p.key.get_pressed()[p.K_DOWN] - p.key.get_pressed()[p.K_UP]) * 5), r[2].move_ip(*b)], [rect.clamp_ip(w.get_rect()) for rect in r[0:2]], setattr(r[2], "topleft", (390, 290) if r[2].x < 0 or r[2].right > 800 else r[2].topleft)][0]: b[1], b[0] = -b[1] if not 0 < r[2].y < 540 else b[1], -b[0] if r[2].collidelist(r[:2]) >= 0 else b[0]
# Alternative implementation of pygame.Rect that uses floats rather than integers
#
# Use FRect from pygame-ce instead of this!
# https://pyga.me/docs/ref/rect.html
#
# Don't question the implementation strategy, this is perfect
# Repurposed from another project of mine
# Constants needed for my direct translation of SDL_IntersectRectAndLine