Add light colour wedges transforms.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 14:17:22 +0000 (16:17 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 14:17:22 +0000 (16:17 +0200)
tabakrolletjie/transforms.py

index 88f516169e02dfe46ff22523eb28a353ad421a75..8590c1bbd1ee61539921e9d906cfdf96f9fbb890 100644 (file)
@@ -4,6 +4,8 @@ import pygame.surface
 
 import pygame.locals as pgl
 
+from .constants import COLOURS
+
 
 class Transform(object):
 
@@ -74,3 +76,33 @@ class Alpha(Transform):
     def apply(self, surface):
         surface.fill((255, 255, 255, self.alpha), None, pgl.BLEND_RGBA_MULT)
         return surface
+
+
+class ColourWedges(Transform):
+    """ Apply colours as wedges. """
+
+    ARGS = ["colours"]
+
+    def apply(self, surface):
+        size = surface.get_width()
+        assert size in (16, 32, 48, 64)
+        fitting_colours = [COLOURS[c] for c in self.colours]
+        ncolour = len(fitting_colours)
+        if ncolour > 3:
+            print "Multicoloured light should not have more than 3 colours"
+            ncolour = 3
+
+        if ncolour == 1:
+            multiply = Multiply(colour=fitting_colours[0])
+            return multiply.apply(surface)
+
+        colour_mult_image = pygame.surface.Surface((size, size))
+        from .loader import loader
+        for i in range(ncolour):
+            sector = loader.load_image(
+                str(size), "light_mask_%d_%d.png" % (ncolour, i + 1),
+                transform=Multiply(colour=fitting_colours[i]))
+            colour_mult_image.blit(sector, (0, 0), None, 0)
+
+        surface.blit(colour_mult_image, (0, 0), None, pgl.BLEND_RGBA_MULT)
+        return surface