Pages

Se afișează postările cu eticheta modules. Afișați toate postările
Se afișează postările cu eticheta modules. Afișați toate postările

sâmbătă, 8 aprilie 2023

PyGame : ovoid with a random pattern.

Here's how to create an ovoid with a random pattern. Run the script several times to see the differences:
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()

luni, 9 februarie 2009

About Pygame python module.

About PYGAME we can find out from web articles and we can get a picture of this python module:
Yet another powerful open source 2D game engine. Pygame is a set of modules allows you to create fully featured games and multimedia programs in the python language. Pygame is portable and runs on every platform and operating system.
Pygame is free. Released under the LGPL license, you can create an open source, free, freeware, shareware, and commercial games with it. See the license for full details.

The Python PyGame module is easy to use in both procedural and object programming.
The installation process is easy:
pip install pygame
The official web page can be found here.
The Wikipedia page with info about this python module can be found here.
The pypi webpage can be found here.
All documentation can be found on this webpage.