From 1cdc29cb8d944e3a25bb8518e00842201e6b9285 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 00:34:14 +0200 Subject: [PATCH] Add pulsating lamp. --- data/stations/station-alpha.json | 8 ++++++++ tabakrolletjie/lights.py | 23 +++++++++++++++++++++++ tabakrolletjie/rays.py | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/data/stations/station-alpha.json b/data/stations/station-alpha.json index 84b3910..7692adc 100644 --- a/data/stations/station-alpha.json +++ b/data/stations/station-alpha.json @@ -45,6 +45,14 @@ "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 } ] } diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 6f39b70..2365220 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -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" diff --git a/tabakrolletjie/rays.py b/tabakrolletjie/rays.py index 6ff8a6e..6e98d83 100644 --- a/tabakrolletjie/rays.py +++ b/tabakrolletjie/rays.py @@ -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): -- 2.34.1