-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
65 lines (48 loc) · 1.77 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from itertools import cycle
import numpy as np
import pygame
from pygame._sdl2.video import Renderer, Texture
pygame.init()
screen = pygame.Window()
renderer = Renderer(screen, accelerated=1)
clock = pygame.Clock()
def create_fading_circle(radius):
"""
Creates a Pygame surface with a circle where the alpha decreases from 255 at the center to 0 at the edge.
:param radius: Radius of the circle
:return: A Pygame surface with the fading circle
"""
diameter = int(radius * 2)
surface = pygame.Surface((diameter, diameter), pygame.SRCALPHA)
for y in range(diameter):
for x in range(diameter):
dx = x - radius
dy = y - radius
distance = np.sqrt(dx**2 + dy**2)
if distance <= radius:
alpha = max(0, int(255 * (1 - distance / radius)))
surface.set_at((x, y), (255, 255, 255, alpha))
return surface
surf = pygame.image.load("assets/bug_alpha.png")
surf = pygame.transform.scale_by(surf, 0.25)
bloom = create_fading_circle(surf.get_width() / 2)
size = surf.get_size()
surf.blit(bloom, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
texture = Texture.from_surface(renderer, surf)
temp = pygame.Surface((300, 200))
temp.fill("green")
rectangle = Texture.from_surface(renderer, temp)
temp = pygame.Surface(screen.size, pygame.SRCALPHA)
temp.fill("black")
temp.set_alpha(200)
overlay = Texture.from_surface(renderer, temp)
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
raise SystemExit
renderer.clear()
renderer.blit(rectangle, pygame.Rect(300, 200, 300, 200))
renderer.blit(overlay, pygame.Rect(0, 0, *screen.size))
renderer.blit(texture, pygame.Rect(100, 100, *size))
renderer.present()