35 lines
812 B
Python
35 lines
812 B
Python
|
|
import pygame
|
||
|
|
|
||
|
|
pygame.init()
|
||
|
|
screen = pygame.display.set_mode((1280, 720))
|
||
|
|
clock = pygame.time.Clock()
|
||
|
|
running = True
|
||
|
|
|
||
|
|
image = pygame.Surface((200, 200), pygame.SRCALPHA)
|
||
|
|
image.fill("blue")
|
||
|
|
pygame.draw.rect(image, "red", (0, 100, 200, 100))
|
||
|
|
|
||
|
|
selection = pygame.Surface((200, 200), pygame.SRCALPHA)
|
||
|
|
pygame.draw.circle(selection, "white", (100, 100), 80)
|
||
|
|
mask = pygame.mask.from_surface(selection)
|
||
|
|
mask_view = mask.to_surface()
|
||
|
|
|
||
|
|
result = mask.to_surface(setsurface=image, unsetcolor=(0, 0, 0, 0))
|
||
|
|
|
||
|
|
|
||
|
|
while running:
|
||
|
|
for event in pygame.event.get():
|
||
|
|
if event.type == pygame.QUIT:
|
||
|
|
running = False
|
||
|
|
|
||
|
|
screen.fill("grey")
|
||
|
|
|
||
|
|
screen.blit(image, (260, 260))
|
||
|
|
screen.blit(mask_view, (540, 260))
|
||
|
|
screen.blit(result, (820, 260))
|
||
|
|
|
||
|
|
pygame.display.flip()
|
||
|
|
clock.tick(60)
|
||
|
|
|
||
|
|
pygame.quit()
|