def testAntiAliasing(self): renderer = pil_renderer.PILRenderer(image_size=(16, 16), anti_aliasing=5) image = renderer.render(self._get_sprites()) self.assertSequenceEqual(list(image[4, 9]), [0, 0, 0]) # Python2 and Python3 give slightly different anti-aliasing, so we specify # bounds for border values: self.assertTrue(all(image[5, 9] >= [10, 11, 0])) self.assertTrue(all(image[5, 9] <= [33, 23, 0])) self.assertTrue(all(image[6, 9] >= [189, 34, 0])) self.assertTrue(all(image[6, 9] <= [222, 42, 0])) self.assertSequenceEqual(list(image[7, 9]), [255, 0, 0]) renderer = pil_renderer.PILRenderer(image_size=(16, 16), anti_aliasing=1) image = renderer.render(self._get_sprites()) self.assertSequenceEqual(list(image[4, 9]), [0, 0, 0]) self.assertSequenceEqual(list(image[6, 9]), [255, 0, 0]) self.assertSequenceEqual(list(image[7, 9]), [255, 0, 0])
def testColorToRGB(self): s = sprite.Sprite(x=0.5, y=0.5, shape='square', c0=0.2, c1=0.5, c2=0.5) def _color_to_rgb(c): return tuple((255 * np.array(colorsys.hsv_to_rgb(*c))).astype(np.uint8)) renderer = pil_renderer.PILRenderer( image_size=(64, 64), color_to_rgb=_color_to_rgb) image = renderer.render([s]) self.assertSequenceEqual(list(image[32, 32]), [114, 127, 63])
def testBackground(self): bg_color = (5, 6, 7) renderer = pil_renderer.PILRenderer(image_size=(64, 64), bg_color=bg_color) image = renderer.render(self._get_sprites()) self.assertSequenceEqual(list(image[5, 5]), bg_color)
def testOcclusion(self): renderer = pil_renderer.PILRenderer(image_size=(64, 64)) image = renderer.render(self._get_sprites()) self.assertSequenceEqual(list(image[32, 44]), [255, 0, 0]) self.assertSequenceEqual(list(image[32, 47]), [0, 255, 0])
def testBasicFunctionality(self): renderer = pil_renderer.PILRenderer(image_size=(64, 64)) renderer.render(self._get_sprites())