From 5cbe7a3f0a931b8feeb1e6e72b7a4f1c985a434e Mon Sep 17 00:00:00 2001 From: adrianna Date: Sat, 10 Sep 2016 12:39:21 +0200 Subject: [PATCH] multicoloured light display --- data/images/32/light_mask_2_1.png | Bin 0 -> 179 bytes data/images/32/light_mask_2_2.png | Bin 0 -> 182 bytes data/images/32/light_mask_3_1.png | Bin 0 -> 269 bytes data/images/32/light_mask_3_2.png | Bin 0 -> 327 bytes data/images/32/light_mask_3_3.png | Bin 0 -> 280 bytes data/images/48/light_mask_2_1.png | Bin 0 -> 214 bytes data/images/48/light_mask_2_2.png | Bin 0 -> 216 bytes data/images/48/light_mask_3_1.png | Bin 0 -> 334 bytes data/images/48/light_mask_3_2.png | Bin 0 -> 416 bytes data/images/48/light_mask_3_3.png | Bin 0 -> 359 bytes data/images/Makefile | 8 ++-- sources/vector/light_mask_2_1.svg | 77 ++++++++++++++++++++++++++++++ sources/vector/light_mask_2_2.svg | 77 ++++++++++++++++++++++++++++++ sources/vector/light_mask_3_1.svg | 77 ++++++++++++++++++++++++++++++ sources/vector/light_mask_3_2.svg | 77 ++++++++++++++++++++++++++++++ sources/vector/light_mask_3_3.svg | 77 ++++++++++++++++++++++++++++++ tabakrolletjie/lights.py | 37 +++++++++----- tabakrolletjie/transforms.py | 10 ++++ 18 files changed, 425 insertions(+), 15 deletions(-) create mode 100644 data/images/32/light_mask_2_1.png create mode 100644 data/images/32/light_mask_2_2.png create mode 100644 data/images/32/light_mask_3_1.png create mode 100644 data/images/32/light_mask_3_2.png create mode 100644 data/images/32/light_mask_3_3.png create mode 100644 data/images/48/light_mask_2_1.png create mode 100644 data/images/48/light_mask_2_2.png create mode 100644 data/images/48/light_mask_3_1.png create mode 100644 data/images/48/light_mask_3_2.png create mode 100644 data/images/48/light_mask_3_3.png create mode 100644 sources/vector/light_mask_2_1.svg create mode 100644 sources/vector/light_mask_2_2.svg create mode 100644 sources/vector/light_mask_3_1.svg create mode 100644 sources/vector/light_mask_3_2.svg create mode 100644 sources/vector/light_mask_3_3.svg 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 0000000000000000000000000000000000000000..e95ffee3d302a7c58d853e875eed6a7cce9d95c1 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq z7#%>Eanna5KcJvwiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0upo-U3d z5v^~}ZRBNO;5cmX;Q##7g0XXLCzYR?wB+Y{)-8-cMM%KLuad=P`oSp;ATdu@KbLh* G2~7a##4rB< literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..82fc4ab4ec2151646acadd4fb20564f3f2aca63e GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq z7#%>Eanna5KcJvwiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0wJzf1= J);T3K0RX$!GQ$7> literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c4316c641461a2818a3c7f1a45103a06bad1ee39 GIT binary patch literal 269 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq z7#%>Eanna5KcJvwiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0vro-U3d z5v^~}DGD_PO0+)wJ$s?%BH0()6uP!8i0aNzH%s7Lq>yd&S)+c()arD*htEanna5KcJvwiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0vVJY5_^ zB3j>GUhl=iC~)B6&E0AoY^NJz1bp0PAAKPlp&wP-+8y2-w)pF!t7Qk%wsDAcH_d7K zF3DFIY4cxaclONptaZ%B!V`nMG?#`5ml+&YE!)kLpU||^f4#-wwAl~k+;(ig#q4(> z->Rb1hZ#71r&ZX35F=YMA&4`%!?(%;dso?nUm1f$g#KFzp#i6noM RSwR0Vc)I$ztaD0e0sx%acR&CD literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..da894e708035a8b7e1ba4ed4ee55601b27de4496 GIT binary patch literal 280 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmSQK*5Dp-y;YjHK@;M7UB8wRq z7#%>Eanna5KcJvwiEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$Qb0vhJzX3_ zB3j>G+bHPhDAIN@wo|a9H7cM%Y>UE`rVw4HPz?umC*z=r6O;uxW_-N!eb1ABKj*%8 zv5sEI5|+Jo;%~<%J9^}flp?O}!U0p4hzC{A;hH-_1! ze^ei|s5<@M7tau$WAIAn4`ab`zRTwh=QFUM`7c(-IA^1ieZSDLy)DH%?-cW^FB1tY TI~{i#=s*TfS3j3^P64EsL+oObq1&bR+(e{l0=kOIZ$Y-Nd2{8G#gG@ilJ L)z4*}Q$iB}xdJ|O literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..8d7ab244a302147b2c2f2632355775809db32d4f GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z7$1NzBkQaAoR)604=nHkh3%k#~dsm#1_H5JtxMTkl7Nn5?zcH@rWJySP`_>z1 O0fVQjpUXO@geCyF{Y~%y literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..7c8e0cad0e917efd2e91a6fe45e080f0c6f17281 GIT binary patch literal 334 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z7$1NzBkQaAo?1y2cv^9-gQDq@|ftYIsT7_o9cFq|st(X{%YgB;KQCCndc zr*nVj`Ec*An4#f}qI%1xKV+;FqS;ekH{{4pSj)Vr)L|RniEE5EVS>dhF|J3-+N>`h z6nyvLVgFg#qAuQjUTiWgF%Nd;9B@2gT9(ROr`%WAUwg8FF}>nQIgpxOp(!mO*vOjq zAJ7nJFkSdEa@oH|0QsaL%Ux8Edy*`?p>G2UlTdMZg0w Qptl%2UHx3vIVCg!08IFKBme*a literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..beff2795b2df70406a2367df40fdbdcbeded7200 GIT binary patch literal 416 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z7$1NzBkQaAor3_7^O^nqeB1Zy=##)_iu^k}0l6 z6XZV{)lB|;Hn#lT@$|~L`h&k$o_}5$#HH9G;KTtY7PfEbu=3k5XZP~l83*Lz{!|=h zTvq(uv{f;raQV*aH%S)d@AV^&yLNxrUVy)v*_;*{q&)~lAkB+3LwtNPA z-gthz?q=P4|48Vu51XVzZga*TDtvY$%x~kT@E=o>rtVEYn|;3h(YG^8rUbECYc7rQ y%G|WLeA<0yua#kqcU14bIDb)MfrP?#IMSbf^Y`YB*1Vv&VDNPHb6Mw<&;$SqqqUd- literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c3e4fdafaf548fbaa49bd5f0d8474b01972ff33f GIT binary patch literal 359 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCmSQK*5Dp-y;YjHK@;M7UB8wRq z7$1NzBkQaAoY z6;C$7_xA($C>tQ^5GlVfB=Utn6zV@>U+^=DNY?tnljpc?m}K1gz-fMVy_DAmpi|>7#xcs5?g7x>N vcw7Bp=xJP4<)8P`I)7F9jF~fU+V5f%y;wTA#qW$a(7z0xu6{1-oD!M + + + + + + + + + + + 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. """ -- 2.34.1