Saturday, December 27, 2025

Detective

 Playing with Copilot and PyCharm to create the rudiments of what could be

an identification game. One only sees through the circle - and it is pink - 

but the aim is to guess the work. One is free to move the circle with the arrow 

keys. Below:

                                                                           




The Code:

import pygame

pygame.init()

# Window setup
WIDTH, HEIGHT = 900, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Image Reveal Through Moving Circle")

# Colors
GREY = (150, 150, 150)
PINK = (255, 105, 180)
radius = 50
x, y = WIDTH // 2, HEIGHT // 2
speed = 5

# Load and scale the image so it fits the frame
image = pygame.image.load("Images/Monet.png").convert_alpha()
image = pygame.transform.smoothscale(image, (WIDTH, HEIGHT))

# Create a circular mask surface
mask_surface = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA)
pygame.draw.circle(mask_surface, (255, 255, 255, 255), (radius, radius), radius)

# Circle overlay (pink, low opacity)
circle_overlay = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA)
pygame.draw.circle(circle_overlay, (255, 105, 180, 80), (radius, radius), radius)

clock = pygame.time.Clock()
running = True

while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# Movement
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]: x -= speed
if keys[pygame.K_RIGHT]: x += speed
if keys[pygame.K_UP]: y -= speed
if keys[pygame.K_DOWN]: y += speed

# Draw background
screen.fill(GREY)

# Reveal the image only through the circle mask
# 1. Create a temporary surface
reveal_surface = pygame.Surface((radius*2, radius*2), pygame.SRCALPHA)

# 2. Copy the corresponding part of the image
reveal_surface.blit(image, (-x + radius, -y + radius))

# 3. Apply the circular mask
reveal_surface.blit(mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)

# 4. Blit the revealed portion to the screen
screen.blit(reveal_surface, (x - radius, y - radius))

# Draw the pink circle on top
screen.blit(circle_overlay, (x - radius, y - radius))

pygame.display.flip()
clock.tick(60)

pygame.quit()


Copilot knows what to do immediately when I specify something; I am almost ashamed of how 

slow I am...



No comments: