示例#1
0
 def create_shadow(self, scale=1.0, darkness=1.0, iters=5):
     im = get_pil_image(self.image)
     shalpha = im.split()[-1].convert("L")
     for i in range(iters):
         shalpha = shalpha.filter(ImageFilter.BLUR)
     shalpha=Image.eval(shalpha, lambda x:x*darkness)
     shimg=Image.new("RGBA", self.image.get_size())
     #shimg=shimg.convert("RGBA")
     shimg.putalpha(shalpha)
     return pygame.image.frombuffer(shimg.tostring(), self.image.get_size(), "RGBA")
示例#2
0
    def apply_lightmap(self):
        sun_direction = math.pi*0.75
        lighting_direction = sanitize_angle(self.heading+sun_direction)

        # figure out which one of the prerendered lightmaps to use
        h = int(lighting_direction/(2*math.pi)*len(self.lightmaps*2))
        if 0 <= h < len(self.lightmaps):
            lm = self.lightmaps[h]
        else:
            lm = self.lightmaps[2*len(self.lightmaps)-h-1].transpose(Image.FLIP_TOP_BOTTOM)

        im = get_pil_image(self.image)
        img = im.convert("L")

        # apply lightmap
        limg = ImageChops.multiply(img, lm).convert("RGBA")
        limg.putalpha(im.split()[-1])

        return pygame.image.frombuffer(limg.tostring(), self.image.get_size(), "RGBA")