From c20097e90c03cecb3740bd1d950275a79594d676 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 16:17:22 +0200 Subject: [PATCH] Add light colour wedges transforms. --- tabakrolletjie/transforms.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tabakrolletjie/transforms.py b/tabakrolletjie/transforms.py index 88f5161..8590c1b 100644 --- a/tabakrolletjie/transforms.py +++ b/tabakrolletjie/transforms.py @@ -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 -- 2.34.1