Example with PyGame with 3D features ...
The project can be found on the GitHub repo - stage 11 ...
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()