PyGameネガカラー/表面
Aug 31 2020
PyGameでゲームを作成しています。そこで、すべての画面がネガティブになるネガティブな効果を作りたいと思います。
これは、rectsのような単純な形状の場合は非常に簡単です:(およびの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
回答
4 Rabbid76 Aug 31 2020 at 13:35
これに pygame.Surface.blitは、special_flag引数とともに使用できますBLEND_SUB。
同じサイズの完全に白い画像を作成し、元の画像を差し引きます。
neg = pygame.Surface(image.get_size())
neg.fill((255, 255, 255))
neg.blit(image, (0, 0), special_flags=pygame.BLEND_SUB)