+class Lamp(BaseLight):
+
+ FITTING_IMG = "lamp.png"
+ BASE_COST = 1
+ NAME = "lamp"
+
+
+class PulsatingLamp(BaseLight):
+
+ FITTING_IMG = "pulsatinglamp.png"
+ DEFAULT_PULSE_RANGE = (20, 100)
+ DEFAULT_PULSE_VELOCITY = 2
+ DEFAULT_INTENSITY_RANGE = (0.0, 0.9)
+ DEFAULT_INTENSITY_VELOCITY = 0.1
+ BASE_COST = 3
+ NAME = "pulsating lamp"
+
+ def __init__(self, **kw):
+ 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__(
+ bounding_radius=self.pulse_range[1], **kw)
+
+ def serialize(self):
+ result = super(PulsatingLamp, self).serialize()
+ result["pulse_velocity"] = self.pulse_velocity
+ result["intensity_range"] = self.intensity_range
+ result["intensity_velocity"] = self.intensity_velocity
+ return result
+
+ 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):
+ 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)
+
+ @classmethod
+ def find_cost(cls, config):
+ cost = super(PulsatingLamp, cls).find_cost(config)
+ cost += config.get("pulse_velocity", cls.DEFAULT_PULSE_VELOCITY)
+ pr = config.get("pulse_range", cls.DEFAULT_PULSE_RANGE)
+ cost += (pr[1] - pr[0]) / 10
+ cost += 5 * config.get("intensity_velocity", cls.DEFAULT_INTENSITY_VELOCITY)
+ ir = config.get("intensity_range", cls.DEFAULT_INTENSITY_RANGE)
+ cost += 5 * (ir[1] - ir[0])
+ return cost
+
+ @classmethod
+ def get_info(cls, config):
+ pr = config.get("pulse_range", cls.DEFAULT_PULSE_RANGE)
+ pv = config.get("pulse_velocity", cls.DEFAULT_PULSE_VELOCITY)
+ ir = config.get("intensity_range", cls.DEFAULT_INTENSITY_RANGE)
+ iv = config.get("intensity_velocity", cls.DEFAULT_INTENSITY_VELOCITY)
+ return [
+ "intensity: %g - %g, velocity %g" % (ir[0], ir[1], iv),
+ "pulse: %d - %d, velocity %g" % (pr[0], pr[1], pv),
+ ]
+
+