Add utility for loading a light.
[tabakrolletjie.git] / tabakrolletjie / lights.py
1 """ May it be a light for you in dark places, when all other lights go out.
2 """
3
4
5 class BaseLight(object):
6     """ Common light functionality. """
7
8     def __init__(self, colour, position):
9         self.colour = colour
10         self.position = position
11
12     @classmethod
13     def load(cls, config):
14         kw = config.copy()
15         light_type = kw.pop("type")
16         [light_class] = [
17             c for c in cls.__subclasses__()
18             if c.__name__.lower() == light_type]
19         return light_class(**kw)
20
21
22 class SpotLight(BaseLight):
23     def __init__(
24             self, colour="white", position=None, direction=90.0, spread=45.0):
25         super(SpotLight, self).__init__(colour, position)
26         self.direction = direction
27         self.spread = spread
28
29
30 class Lamp(BaseLight):
31     def __init__(self, colour="white", position=None, radius=100.0):
32         super(Lamp, self).__init__(colour, position)
33         self.radius = radius