X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Flights.py;h=92b66e0a8d4b91907fdec632724e00b0ffa9fba8;hb=d4d66b09aeef6f9973b15e8cc6d04883a9f6f339;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=f3600c28cd6e96abe7c0916860b0cc56b444545f;p=tabakrolletjie.git diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index e69de29..92b66e0 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -0,0 +1,45 @@ +""" May it be a light for you in dark places, when all other lights go out. +""" + +import pymunk + + +class BaseLight(object): + """ Common light functionality. """ + + def __init__(self, colour, position): + self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC) + self.colour = colour + self.position = position + + def add_to_space(self, space): + space.remove(self.body, **self.body.shapes()) + shapes = self.determine_ray_polys(space) + space.add(self.body, **shapes) + + def determine_ray_polys(self, space): + raise NotImplementedError( + "Lights should implement .determine_ray_polys.") + + @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