_surface_cache = {}
def __init__(
- self, colour, position, intensity=1.0, radius_limits=None,
+ self, colours, position, intensity=1.0, radius_limits=None,
direction=None, spread=None):
- self.colour = colour
+ self.colour_cycle = colours
+ self.colour_pos = 0
+ self.colour = colours[0]
self.on = True
self.intensity = intensity
self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC)
self.ray_manager.set_space(space)
self.ray_manager.update_shapes()
- def toggle(self):
- self.on = not self.on
-
def _cached_surface(self, name, surface):
surf = self._surface_cache.get(name)
if surf is None:
rx, ry = self.ray_manager.pygame_position(surface)
surface.blit(self.fitting_image(), (rx - 24, ry - 24), None, 0)
+ def toggle(self):
+ self.colour_pos += 1
+ if self.colour_pos >= len(self.colour_cycle):
+ self.colour = self.colour_cycle[0]
+ self.colour_pos = -1
+ self.on = False
+ else:
+ self.colour = self.colour_cycle[self.colour_pos]
+ self.on = True
+ self.invalidate_fitting_image()
+
def tick(self):
pass
class MultiColourLamp(BaseLight):
FITTING_IMG = "lamp.png"
- DEFAULT_COLOURS = sorted(COLOURS.keys())
def __init__(self, **kw):
- self.colour_cycle = kw.pop("colours", None)
- self.colour_pos = 0
- kw["colour"] = self.colour_cycle[0]
super(MultiColourLamp, self).__init__(**kw)
- def toggle(self):
- self.colour_pos += 1
- if self.colour_pos >= len(self.colour_cycle):
- self.colour = self.colour_cycle[0]
- self.colour_pos = -1
- self.on = False
- else:
- self.colour = self.colour_cycle[self.colour_pos]
- self.on = True
- self.invalidate_fitting_image()
-
class PulsatingLamp(BaseLight):