From: adrianna Date: Sat, 10 Sep 2016 10:39:21 +0000 (+0200) Subject: multicoloured light display X-Git-Tag: tabakrolletjie-v1.0.0~127^2~1 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=5cbe7a3f0a931b8feeb1e6e72b7a4f1c985a434e;p=tabakrolletjie.git multicoloured light display --- diff --git a/data/images/32/light_mask_2_1.png b/data/images/32/light_mask_2_1.png new file mode 100644 index 0000000..e95ffee Binary files /dev/null and b/data/images/32/light_mask_2_1.png differ diff --git a/data/images/32/light_mask_2_2.png b/data/images/32/light_mask_2_2.png new file mode 100644 index 0000000..82fc4ab Binary files /dev/null and b/data/images/32/light_mask_2_2.png differ diff --git a/data/images/32/light_mask_3_1.png b/data/images/32/light_mask_3_1.png new file mode 100644 index 0000000..c4316c6 Binary files /dev/null and b/data/images/32/light_mask_3_1.png differ diff --git a/data/images/32/light_mask_3_2.png b/data/images/32/light_mask_3_2.png new file mode 100644 index 0000000..9b69af2 Binary files /dev/null and b/data/images/32/light_mask_3_2.png differ diff --git a/data/images/32/light_mask_3_3.png b/data/images/32/light_mask_3_3.png new file mode 100644 index 0000000..da894e7 Binary files /dev/null and b/data/images/32/light_mask_3_3.png differ diff --git a/data/images/48/light_mask_2_1.png b/data/images/48/light_mask_2_1.png new file mode 100644 index 0000000..245f371 Binary files /dev/null and b/data/images/48/light_mask_2_1.png differ diff --git a/data/images/48/light_mask_2_2.png b/data/images/48/light_mask_2_2.png new file mode 100644 index 0000000..8d7ab24 Binary files /dev/null and b/data/images/48/light_mask_2_2.png differ diff --git a/data/images/48/light_mask_3_1.png b/data/images/48/light_mask_3_1.png new file mode 100644 index 0000000..7c8e0ca Binary files /dev/null and b/data/images/48/light_mask_3_1.png differ diff --git a/data/images/48/light_mask_3_2.png b/data/images/48/light_mask_3_2.png new file mode 100644 index 0000000..beff279 Binary files /dev/null and b/data/images/48/light_mask_3_2.png differ diff --git a/data/images/48/light_mask_3_3.png b/data/images/48/light_mask_3_3.png new file mode 100644 index 0000000..c3e4fda Binary files /dev/null and b/data/images/48/light_mask_3_3.png differ diff --git a/data/images/Makefile b/data/images/Makefile index c9077ba..641c3e5 100644 --- a/data/images/Makefile +++ b/data/images/Makefile @@ -1,16 +1,18 @@ VPATH=../../sources/vector +SEED=seed TURNIP=turnip1 turnip2 turnip3 MOULD_BODY=mouldA mouldB mouldC MOULD=eyeballA eyeballB eyeballC LIGHT=spotlight lamp laser +LIGHT_MASK=light_mask_2_1 light_mask_2_2 light_mask_3_1 light_mask_3_2 light_mask_3_3 IMG16=$(MOULD_BODY) -IMG32=$(MOULD_BODY) $(MOULD) $(LIGHT) seed -IMG48=$(LIGHT) $(TURNIP) +IMG32=$(MOULD_BODY) $(MOULD) $(LIGHT) $(SEED) $(LIGHT_MASK) +IMG48=$(LIGHT) $(TURNIP) $(LIGHT_MASK) IMG64=$(MOULD_BODY) -CURSORS=seed $(LIGHT) +CURSORS=$(SEED) $(LIGHT) PNG16=$(patsubst %, 16/%.png, $(IMG16)) PNG32=$(patsubst %, 32/%.png, $(IMG32)) diff --git a/sources/vector/light_mask_2_1.svg b/sources/vector/light_mask_2_1.svg new file mode 100644 index 0000000..728794b --- /dev/null +++ b/sources/vector/light_mask_2_1.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_2_2.svg b/sources/vector/light_mask_2_2.svg new file mode 100644 index 0000000..a795c14 --- /dev/null +++ b/sources/vector/light_mask_2_2.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_3_1.svg b/sources/vector/light_mask_3_1.svg new file mode 100644 index 0000000..19e6ab7 --- /dev/null +++ b/sources/vector/light_mask_3_1.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_3_2.svg b/sources/vector/light_mask_3_2.svg new file mode 100644 index 0000000..98ecf9f --- /dev/null +++ b/sources/vector/light_mask_3_2.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/sources/vector/light_mask_3_3.svg b/sources/vector/light_mask_3_3.svg new file mode 100644 index 0000000..a3071b4 --- /dev/null +++ b/sources/vector/light_mask_3_3.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 03adf38..b2e0812 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -12,7 +12,7 @@ from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY, COLOURS from .rays import RayPolyManager from .utils import DetailedTimer from .loader import loader -from .transforms import Multiply +from .transforms import Multiply, MultiplyImage LIGHT_FILTER = pymunk.ShapeFilter( mask=pymunk.ShapeFilter.ALL_MASKS ^ ( @@ -124,6 +124,7 @@ class BaseLight(object): self.body, self.FITTING_RADIUS, self.ray_manager.position) self.fitting.filter = FITTINGS_FILTER self._fitting_image = None + self._colour_mult_image = None @property def position(self): @@ -200,10 +201,30 @@ class BaseLight(object): def fitting_image(self): if self._fitting_image is None: - fitting_colour = COLOURS[self.colour] - self._fitting_image = loader.load_image( + fitting_colours = [COLOURS[c] for c in self.colour_cycle] + ncolour = len(fitting_colours) + if ncolour > 3: + print "Multicoloured light should not have more than 3 colours" + ncolour = 3 + + if ncolour == 1: + self._fitting_image = loader.load_image( "48", self.FITTING_IMG, - transform=Multiply(colour=fitting_colour)) + transform=Multiply(colour=fitting_colours[0])) + else: + if self._colour_mult_image is None: + self._colour_mult_image = pygame.surface.Surface((48, 48)) + + for i in range(ncolour): + sector = loader.load_image( + "48", "light_mask_%d_%d.png" % (ncolour, i + 1), + transform=Multiply(colour=fitting_colours[i])) + self._colour_mult_image.blit(sector, (0,0), None, 0) + + self._fitting_image = loader.load_image( + "48", self.FITTING_IMG, + transform=MultiplyImage(image=self._colour_mult_image)) + return self._fitting_image def invalidate_fitting_image(self): @@ -233,14 +254,6 @@ class Lamp(BaseLight): FITTING_IMG = "lamp.png" -class MultiColourLamp(BaseLight): - - FITTING_IMG = "lamp.png" - - def __init__(self, **kw): - super(MultiColourLamp, self).__init__(**kw) - - class PulsatingLamp(BaseLight): FITTING_IMG = "lamp.png" diff --git a/tabakrolletjie/transforms.py b/tabakrolletjie/transforms.py index 88f5161..50cb1d1 100644 --- a/tabakrolletjie/transforms.py +++ b/tabakrolletjie/transforms.py @@ -66,6 +66,16 @@ class Multiply(Transform): return surface +class MultiplyImage(Transform): + """ Apply a colour by multiplying. """ + + ARGS = ["image"] + + def apply(self, surface): + surface.blit(self.image, (0, 0), None, pgl.BLEND_RGBA_MULT) + return surface + + class Alpha(Transform): """ Make translucent. """