我正在使用PyGame创建一个游戏。我想要创建一个负面效果,使整个屏幕变成负片。
对于简单的形状(如矩形),这非常容易实现:(使用rect
而不是pygame.draw.rect
)
# set negative to 1 to activate effect
negative = 0
def rect(win, color, area, width=0):
if negative:
pygame.draw.rect(win, (255 - color[0], 255 - color[1], 255 - color[2]), area, width)
else:
pygame.draw.rect(win, color, area, width)
但我不知道如何在图像上实现这种效果。我尝试过反转图像复制,但如果该效果不是即时的,而是逐渐填充屏幕,则这将不起作用。
# negative image copy
def negcopy(image):
neg = pygame.Surface(image.get_size())
for y in range(image.get_height()):
for x in range(image.get_width()):
c = image.get_at((x, y)
neg.set_at((x, y), (255 - color[0], 255 - color[1], 255 - color[2], 255))
return neg