added a multiply transform to use on light fittings
authoradrianna <adrianna.pinska@gmail.com>
Fri, 9 Sep 2016 20:22:53 +0000 (22:22 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Fri, 9 Sep 2016 20:23:11 +0000 (22:23 +0200)
tabakrolletjie/lights.py
tabakrolletjie/transforms.py

index f1a69d69cdba4540cea2788a893bea63226c66e3..9f0005d1bb377e7fd3d49b663880feb6eba2d23e 100644 (file)
@@ -12,6 +12,7 @@ from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY
 from .rays import RayPolyManager
 from .utils import DetailedTimer
 from .loader import loader
+from .transforms import Multiply
 
 LIGHT_FILTER = pymunk.ShapeFilter(
     mask=pymunk.ShapeFilter.ALL_MASKS ^ (
@@ -203,9 +204,8 @@ class BaseLight(object):
 
     def get_image(self):
         if self._image is None:
-            self._image = loader.load_image("64", self.FITTING_IMG).copy()
             fitting_colour = self.COLOURS[self.colour]
-            self._image.fill(fitting_colour, None, pgl.BLEND_RGBA_MULT)
+            self._image = loader.load_image("64", self.FITTING_IMG, transform=Multiply(colour=fitting_colour))
         return self._image
 
     def render_fitting(self, surface):
index c5eb05f64e7d85739910eb2f89e1e4f428095070..b748b6e2f545e9a8745f0b869f2c09fde3ddbf4f 100644 (file)
@@ -2,6 +2,8 @@
 
 import pygame.surface
 
+import pygame.locals as pgl
+
 
 class Transform(object):
 
@@ -49,3 +51,16 @@ 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