-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
31 lines (23 loc) · 866 Bytes
/
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
import pygame
pygame.init()
def colorize(image, newColor):
"""
Create a "colorized" copy of a surface (replaces RGB values with the given color, preserving the per-pixel alphas of
original).
:param image: Surface to create a colorized copy of
:param newColor: RGB color to use (original alpha values are preserved)
:return: New colorized Surface instance
"""
image = image.copy()
# zero out RGB values
image.fill((0, 0, 0, 255), None, pygame.BLEND_RGBA_MULT)
# add in new RGB values
image.fill(newColor[0:3] + (0,), None, pygame.BLEND_RGBA_ADD)
return image
screen = pygame.display.set_mode((800, 600))
screen.fill((255, 255, 255))
image = pygame.image.load('./images/1.png').convert_alpha()
screen.blit(colorize(image, (255, 0, 0)), (100, 100))
pygame.display.update()
while True:
pygame.event.pump()