Add pulsating lamp.
authorSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 22:34:14 +0000 (00:34 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 22:34:14 +0000 (00:34 +0200)
data/stations/station-alpha.json
tabakrolletjie/lights.py
tabakrolletjie/rays.py

index 84b391019cf9358633fe5496184fefbe637cadb2..7692adce3ac29bff7097a65f2273b418a125b6dc 100644 (file)
       "colours": ["red", "yellow", "green"],
       "position": [300, 300],
       "intensity": 0.5
+    },
+    {
+      "type": "pulsatinglamp",
+      "colour": "cyan",
+      "pulse_range": [20, 100],
+      "pulse_velocity": 1,
+      "position": [250, 450],
+      "intensity": 0.5
     }
   ]
 }
index 6f39b70876b475e1fe34c3ad3982838f822d6493..2365220ea0099474d668d470dc29d500cfc306e6 100644 (file)
@@ -255,6 +255,29 @@ class MultiColourLamp(BaseLight):
         self.invalidate_fitting_image()
 
 
+class PulsatingLamp(BaseLight):
+
+    FITTING_IMG = "lamp.png"
+    DEFAULT_RANGE = (20, 100)
+    DEFAULT_VELOCITY = 2
+
+    def __init__(self, **kw):
+        self.pulse_range = kw.pop("pulse_range", self.DEFAULT_RANGE)
+        self.pulse_velocity = kw.pop("pulse_velocity", self.DEFAULT_VELOCITY)
+        super(PulsatingLamp, self).__init__(**kw)
+
+    def tick(self):
+        radius = self.ray_manager.max_radius
+        radius += self.pulse_velocity
+        if radius < self.pulse_range[0]:
+            radius = self.pulse_range[0]
+            self.pulse_velocity = -self.pulse_velocity
+        elif radius > self.pulse_range[1]:
+            radius = self.pulse_range[1]
+            self.pulse_velocity = -self.pulse_velocity
+        self.ray_manager.max_radius = radius
+
+
 class SpotLight(BaseLight):
 
     FITTING_IMG = "spotlight.png"
index 6ff8a6ea526033de129d82aafe735a35ef71a213..6e98d83337d646f39f1d4c5d27f06e1c42f906d5 100644 (file)
@@ -114,7 +114,7 @@ class RayPolyManager(object):
         return self._max_radius
 
     @max_radius.setter
-    def max_radius_setter(self, value):
+    def max_radius(self, value):
         self._max_radius = value or 0.0
 
     @property
@@ -122,7 +122,7 @@ class RayPolyManager(object):
         return self._min_radius
 
     @min_radius.setter
-    def min_radius_setter(self, value):
+    def min_radius(self, value):
         self._min_radius = value or 0.0
 
     def reaches(self, position):