Add a blend_add transform
authorNeil <neil@dip.sun.ac.za>
Thu, 15 May 2014 22:09:54 +0000 (00:09 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 15 May 2014 22:09:54 +0000 (00:09 +0200)
naja/resources/mutators.py

index 382e7c77555edaf0f60e633dab9042c2aa584173..36ef2297671d7cc5382d93d6f68430eea163faf3 100644 (file)
@@ -4,6 +4,9 @@ from pygame.transform import flip, rotate, scale
 
 from naja.constants import EIGHT_BIT_SCALE
 
+from pygame import surface
+import pygame.locals as pgl
+
 
 class Mutator(object):
     def __init__(self, func, *args):
@@ -38,6 +41,20 @@ def scale_multiplier(image, factor):
     return scale(image, size)
 
 
+def blend_add(image, colour):
+    """Overlay the image with the given colour using BLEND_ADD"""
+    blend = surface.Surface(image.get_size())
+    blend.fill(colour)
+    # We return a copy
+    blended_image = image.copy()
+    blended_image.blit(blend, (0, 0), special_flags=pgl.BLEND_ADD)
+    return blended_image
+
+
+def blender(colour):
+    return Mutator(blend_add, tuple(colour))
+
+
 # Identity mutator
 NULL = Mutator(lambda x: x)