Skip to content

Commit 2876446

Browse files
committed
add alpha test
1 parent f42f9ed commit 2876446

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/test_alpha.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# /// script
2+
# dependencies = [
3+
# "pygame-ce",
4+
# ]
5+
# ///
6+
7+
import pygame
8+
import asyncio
9+
import platform, sys
10+
11+
if sys.platform in ('emscripten', 'wasi'):
12+
platform.document.body.style.background = "#00FF00"
13+
platform.window.canvas.style.imageRendering = "pixelated"
14+
15+
import pygame
16+
pygame.init()
17+
18+
async def main():
19+
screen = pygame.display.set_mode((800, 600))
20+
clock = pygame.time.Clock()
21+
BLUE = pygame.Color('dodgerblue4')
22+
# I just create the background surface in the following lines.
23+
background = pygame.Surface(screen.get_size())
24+
background.fill((90, 120, 140))
25+
for y in range(0, 600, 20):
26+
for x in range(0, 800, 20):
27+
pygame.draw.rect(background, BLUE, (x, y, 20, 20), 1)
28+
29+
# This dark gray surface will be blitted above the background surface.
30+
surface = pygame.Surface(screen.get_size(), pygame.SRCALPHA)
31+
surface.fill(pygame.Color('gray11'))
32+
33+
done = False
34+
while not done:
35+
for event in pygame.event.get():
36+
if event.type == pygame.QUIT:
37+
done = True
38+
elif event.type == pygame.MOUSEMOTION:
39+
surface.fill(pygame.Color('gray11')) # Clear the gray surface ...
40+
# ... and draw a transparent circle onto it to create a hole.
41+
pygame.draw.circle(surface, (255, 255, 255, 0), event.pos, 90)
42+
43+
screen.blit(background, (0, 0))
44+
screen.blit(surface, (0, 0))
45+
46+
pygame.display.flip()
47+
clock.tick(30)
48+
await asyncio.sleep(0)
49+
50+
pygame.quit()
51+
52+
asyncio.run(main())

0 commit comments

Comments
 (0)