Factor light fitting rendering out into a function.
[tabakrolletjie.git] / tabakrolletjie / transforms.py
index c5eb05f64e7d85739910eb2f89e1e4f428095070..88f516169e02dfe46ff22523eb28a353ad421a75 100644 (file)
@@ -2,6 +2,8 @@
 
 import pygame.surface
 
+import pygame.locals as pgl
+
 
 class Transform(object):
 
@@ -49,3 +51,26 @@ class Overlay(Transform):
         over.fill(self.colour)
         surface.blit(over, (0, 0), None)
         return surface
+
+
+class Multiply(Transform):
+    """ Apply a colour by multiplying. """
+
+    ARGS = ["colour"]
+
+    def apply(self, surface):
+        mult = pygame.surface.Surface(surface.get_size())
+        mult = mult.convert_alpha()
+        mult.fill(self.colour)
+        surface.blit(mult, (0, 0), None, pgl.BLEND_RGBA_MULT)
+        return surface
+
+
+class Alpha(Transform):
+    """ Make translucent. """
+
+    ARGS = ["alpha"]
+
+    def apply(self, surface):
+        surface.fill((255, 255, 255, self.alpha), None, pgl.BLEND_RGBA_MULT)
+        return surface