Also pulsate intensity.
authorSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 22:43:32 +0000 (00:43 +0200)
committerSimon Cross <hodgestar@gmail.com>
Fri, 9 Sep 2016 22:43:32 +0000 (00:43 +0200)
data/stations/station-alpha.json
tabakrolletjie/lights.py

index 7692adce3ac29bff7097a65f2273b418a125b6dc..e8e96194f7c62e036451835bf50f6ae907f840b6 100644 (file)
     {
       "type": "pulsatinglamp",
       "colour": "cyan",
-      "pulse_range": [20, 100],
+      "pulse_range": [20, 90],
       "pulse_velocity": 1,
+      "intensity_range": [0.1, 0.8],
+      "intensity_velocity": 0.01,
       "position": [250, 450],
       "intensity": 0.5
     }
index 2365220ea0099474d668d470dc29d500cfc306e6..3c25188db77a944ab70c3fa1b9f706c79c345f7d 100644 (file)
@@ -105,6 +105,7 @@ class BaseLight(object):
         "blue": (0, 0, 255),
         "cyan": (0, 255, 255),
         "yellow": (255, 255, 0),
+        "magenta": (255, 0, 255),
         "white": (255, 255, 255),
     }
 
@@ -258,24 +259,36 @@ class MultiColourLamp(BaseLight):
 class PulsatingLamp(BaseLight):
 
     FITTING_IMG = "lamp.png"
-    DEFAULT_RANGE = (20, 100)
-    DEFAULT_VELOCITY = 2
+    DEFAULT_PULSE_RANGE = (20, 100)
+    DEFAULT_PULSE_VELOCITY = 2
+    DEFAULT_INTENSITY_RANGE = (0.0, 0.9)
+    DEFAULT_INTENSITY_VELOCITY = 0.1
 
     def __init__(self, **kw):
-        self.pulse_range = kw.pop("pulse_range", self.DEFAULT_RANGE)
-        self.pulse_velocity = kw.pop("pulse_velocity", self.DEFAULT_VELOCITY)
+        self.pulse_range = kw.pop("pulse_range", self.DEFAULT_PULSE_RANGE)
+        self.pulse_velocity = kw.pop(
+            "pulse_velocity", self.DEFAULT_PULSE_VELOCITY)
+        self.intensity_range = kw.pop(
+            "intensity_range", self.DEFAULT_INTENSITY_RANGE)
+        self.intensity_velocity = kw.pop(
+            "intensity_velocity", self.DEFAULT_INTENSITY_VELOCITY)
         super(PulsatingLamp, self).__init__(**kw)
 
+    def _update_range(self, value, velocity, value_range):
+        value += velocity
+        if value < value_range[0]:
+            value = value_range[0]
+            velocity = -velocity
+        elif value > value_range[1]:
+            value = value_range[1]
+            velocity = -velocity
+        return value, velocity
+
     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
+        self.ray_manager.max_radius, self.pulse_velocity = self._update_range(
+            self.ray_manager.max_radius, self.pulse_velocity, self.pulse_range)
+        self.intensity, self.intensity_velocity = self._update_range(
+            self.intensity, self.intensity_velocity, self.intensity_range)
 
 
 class SpotLight(BaseLight):