From: Simon Cross Date: Sun, 4 Sep 2016 16:46:39 +0000 (+0200) Subject: Add utility for loading a light. X-Git-Tag: tabakrolletjie-v1.0.0~254 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=e5dd047e68fba0c392f486b9731f7ad5d3e1be6f;p=tabakrolletjie.git Add utility for loading a light. --- diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index e69de29..8ec89a0 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -0,0 +1,33 @@ +""" May it be a light for you in dark places, when all other lights go out. +""" + + +class BaseLight(object): + """ Common light functionality. """ + + def __init__(self, colour, position): + self.colour = colour + self.position = position + + @classmethod + def load(cls, config): + kw = config.copy() + light_type = kw.pop("type") + [light_class] = [ + c for c in cls.__subclasses__() + if c.__name__.lower() == light_type] + return light_class(**kw) + + +class SpotLight(BaseLight): + def __init__( + self, colour="white", position=None, direction=90.0, spread=45.0): + super(SpotLight, self).__init__(colour, position) + self.direction = direction + self.spread = spread + + +class Lamp(BaseLight): + def __init__(self, colour="white", position=None, radius=100.0): + super(Lamp, self).__init__(colour, position) + self.radius = radius