I started a game project with the python packages pygame and agentpy in the Fedora Linux distribution.
You can find it on my fedora pagure repo

windows,linux, tutorials, tutorial, pygame, ,development,programming,source code,code,example,examples,All with pygame python module. The pygame-catalin is a blog created by Catalin George Festila.
pip install pygame
Collecting pygame
Downloading pygame-2.5.2-cp312-cp312-win_amd64.whl.metadata (13 kB)
...
Installing collected packages: pygame
Successfully installed pygame-2.5.2
import pygame
import pygame.gfxdraw
TARGET_SIZE = 200
BG_ALPHA_COLOR = (0, 0, 0, 100)
class Target(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.Surface((TARGET_SIZE, TARGET_SIZE), pygame.SRCALPHA)
self.rect = self.image.get_rect()
self.color = (255, 0, 0)
self.filled = False
self.width = 1
def DrawTarget(self):
pygame.gfxdraw.aacircle(self.image, int(self.rect.width/2), int(self.rect.height/2),\
int(self.rect.width/2 - 1), self.color)
pygame.gfxdraw.filled_ellipse(self.image, int(self.rect.width/2), \
int(self.rect.height/2), int(self.rect.width/2 - 1), int(self.rect.width/2 - 1), self.color)
temp = pygame.Surface((TARGET_SIZE, TARGET_SIZE), pygame.SRCALPHA)
if not self.filled:
pygame.gfxdraw.filled_ellipse(temp, int(self.rect.width/2), int(self.rect.height/2), \
int(self.rect.width/2 - self.width), int(self.rect.width/2 - self.width), BG_ALPHA_COLOR)
pygame.gfxdraw.aacircle(temp, int(self.rect.width/2), int(self.rect.height/2), \
int(self.rect.width/2 - self.width), BG_ALPHA_COLOR)
self.image.blit(temp, (0, 0), None, pygame.BLEND_ADD)
pygame.init()
screen = pygame.display.set_mode((400, 400))
target = Target()
target.DrawTarget()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((255, 255, 255))
screen.blit(target.image, (100, 100))
pygame.display.flip()
pygame.quit()
import pygame
import random
pygame.init()
# Set up the display window
screen_size = (400, 400)
screen = pygame.display.set_mode(screen_size)
# Set window title
pygame.display.set_caption("Ovoid with Random Pattern")
# Define the ovoid
ovoid_pos = (150, 100)
ovoid_size = (100, 200)
# Create the ovoid surface
ovoid_surface = pygame.Surface(ovoid_size, pygame.SRCALPHA)
# Define the pattern
pattern_size = (random.randint(1, 9), random.randint(1, 9))
pattern_surface = pygame.Surface(pattern_size)
pattern_surface.fill((255, 255, 255))
pygame.draw.line(pattern_surface, (0, 0, 0), (0, 0), pattern_size)
# Create the mask surface
mask_surface = pygame.Surface(ovoid_size, pygame.SRCALPHA)
pygame.draw.ellipse(mask_surface, (255, 255, 255), mask_surface.get_rect(), 0)
# Apply the pattern to the ovoid surface
for x in range(0, ovoid_size[0], pattern_size[0]):
for y in range(0, ovoid_size[1], pattern_size[1]):
ovoid_surface.blit(pattern_surface, (x, y))
# Apply the mask to the ovoid surface
ovoid_surface.blit(mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
# Draw the ovoid to the screen
screen.blit(ovoid_surface, ovoid_pos)
# Update the display
pygame.display.flip()
# Wait for the user to close the window
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
# Quit pygame properly
pygame.quit()
C:\PythonProjects\pygamecamera001>pip install pygame --user
Collecting pygame
Downloading pygame-2.2.0-cp311-cp311-win_amd64.whl (10.4 MB)
---------------------------------------- 10.4/10.4 MB 9.0 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.2.0
import pygame.camera
import pygame.image
import sys
pygame.camera.init()
cameras = pygame.camera.list_cameras()
webcam = pygame.camera.Camera(cameras[0])
webcam.start()
img = webcam.get_image()
WIDTH = img.get_width()
HEIGHT = img.get_height()
screen = pygame.display.set_mode( ( WIDTH, HEIGHT ) )
pygame.display.set_caption("pyGame webcam")
while True :
for e in pygame.event.get() :
if e.type == pygame.QUIT :
sys.exit()
screen.blit(img, (0,0))
pygame.display.flip()
img = webcam.get_image()
import pygame
import time
# init the Pygame
pygame.init()
# this set the window size
window_size = (640, 100)
# this create the window
screen = pygame.display.set_mode(window_size)
# this set the title of the window
pygame.display.set_caption("Digital Clock")
# this fill the background color to white
screen.fill((255, 255, 255))
# settings for the font and size
font = pygame.font.Font(None, 36)
# the game loop area
running = True
while running:
# use an event to quit
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# get the current time
current_time = time.strftime("%H:%M:%S")
# render the time as text
text = font.render(current_time, True, (0, 0, 0))
# clear the screen
screen.fill((255, 255, 255))
# draw the text on the screen
screen.blit(text, (10, 10))
# update the screen
pygame.display.flip()
# quit Pygame application
pygame.quit()