# Path: spriteworld/sprite.py
# FACTOR_NAMES = (
#     'x',  # x-position of sprite center-of-mass (float)
#     'y',  # y-position of sprite center-of-mass (float)
#     'shape',  # shape (string)
#     'angle',  # angle in degrees (scalar)
#     'scale',  # size of sprite (float)
#     'c0',  # first color component (scalar)
#     'c1',  # second color component (scalar)
#     'c2',  # third color component (scalar)
#     'x_vel',  # x-component of velocity (float)
#     'y_vel',  # y-component of velocity (float)
# )
# _MAX_TRIES = int(1e6)
# class Sprite(object):
#   def __init__(self,
#                x=0.5,
#                y=0.5,
#                shape='square',
#                angle=0,
#                scale=0.1,
#                c0=0,
#                c1=0,
#                c2=0,
#                x_vel=0.0,
#                y_vel=0.0):
#   def _reset_centered_path(self):
#   def move(self, motion, keep_in_frame=False):
#   def update_position(self, keep_in_frame=False):
#   def contains_point(self, point):
#   def sample_contained_position(self):
#   def vertices(self):
#   def out_of_frame(self):
#   def x(self):
#   def y(self):
#   def shape(self):
#   def shape(self, s):
#   def angle(self):
#   def angle(self, a):
#   def scale(self):
#   def scale(self, s):
#   def c0(self):
#   def c1(self):
#   def c2(self):
#   def x_vel(self):
#   def y_vel(self):
#   def color(self):
#   def position(self):
#   def velocity(self):
#   def factors(self):
# 
# Path: spriteworld/renderers/pil_renderer.py
# class PILRenderer(abstract_renderer.AbstractRenderer):
#   def __init__(self,
#                image_size=(64, 64),
#                anti_aliasing=1,
#                bg_color=None,
#                color_to_rgb=None):
#   def render(self, sprites=(), global_state=None):
#   def observation_spec(self):


import colorsys
import numpy as np
from absl.testing import absltest
from spriteworld import sprite
from spriteworld.renderers import pil_renderer

  def testBasicFunctionality(self):
    renderer = pil_renderer.PILRenderer(image_size=(64, 64))
    renderer.render(self._get_sprites())

  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, 32]), [255, 0, 0])
    self.assertSequenceEqual(list(image[32, 50]), [0, 255, 0])

  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, 6]), [0, 0, 0])
    self.assertSequenceEqual(list(image[6, 6]), [255, 0, 0])
    # Python2 and Python3 give slightly different anti-aliasing, so we specify
    # bounds for border values:
    self.assertTrue(all(image[5, 6] >= [50, 0, 0]))
    self.assertTrue(all(image[5, 6] <= [120, 30, 0]))
    self.assertTrue(all(image[7, 6] >= [200, 0, 0]))
    self.assertTrue(all(image[7, 6] <= [255, 50, 0]))


# Path: spriteworld/sprite.py
# FACTOR_NAMES = (
#     'x',  # x-position of sprite center-of-mass (float)
#     'y',  # y-position of sprite center-of-mass (float)
#     'shape',  # shape (string)
#     'angle',  # angle in degrees (scalar)
#     'scale',  # size of sprite (float)
#     'c0',  # first color component (scalar)
#     'c1',  # second color component (scalar)
#     'c2',  # third color component (scalar)
#     'x_vel',  # x-component of velocity (float)
#     'y_vel',  # y-component of velocity (float)
# )
# _MAX_TRIES = int(1e6)
# class Sprite(object):
#   def __init__(self,
#                x=0.5,
#                y=0.5,
#                shape='square',
#                angle=0,
#                scale=0.1,
#                c0=0,
#                c1=0,
#                c2=0,
#                x_vel=0.0,
#                y_vel=0.0):
#   def _reset_centered_path(self):
#   def move(self, motion, keep_in_frame=False):
#   def update_position(self, keep_in_frame=False):
#   def contains_point(self, point):
#   def sample_contained_position(self):
#   def vertices(self):
#   def out_of_frame(self):
#   def x(self):
#   def y(self):
#   def shape(self):
#   def shape(self, s):
#   def angle(self):
#   def angle(self, a):
#   def scale(self):
#   def scale(self, s):
#   def c0(self):
#   def c1(self):
#   def c2(self):
#   def x_vel(self):
#   def y_vel(self):
#   def color(self):
#   def position(self):
#   def velocity(self):
#   def factors(self):
# 
# Path: spriteworld/renderers/pil_renderer.py
# class PILRenderer(abstract_renderer.AbstractRenderer):
#   def __init__(self,
#                image_size=(64, 64),
#                anti_aliasing=1,
#                bg_color=None,
#                color_to_rgb=None):
#   def render(self, sprites=(), global_state=None):
#   def observation_spec(self):


# Path: tests/renderers/pil_renderer_test.py
import colorsys
import numpy as np
from absl.testing import absltest
from spriteworld import sprite
from spriteworld.renderers import pil_renderer


  def testBasicFunctionality(self):
    renderer = pil_renderer.PILRenderer(image_size=(64, 64))
    renderer.render(self._get_sprites())

  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, 32]), [255, 0, 0])
    self.assertSequenceEqual(list(image[32, 50]), [0, 255, 0])

  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, 6]), [0, 0, 0])
    self.assertSequenceEqual(list(image[6, 6]), [255, 0, 0])
    # Python2 and Python3 give slightly different anti-aliasing, so we specify
    # bounds for border values:
    self.assertTrue(all(image[5, 6] >= [50, 0, 0]))
    self.assertTrue(all(image[5, 6] <= [120, 30, 0]))
    self.assertTrue(all(image[7, 6] >= [200, 0, 0]))
    self.assertTrue(all(image[7, 6] <= [255, 50, 0]))


    renderer = pil_renderer.PILRenderer(image_size=(16, 16), anti_aliasing=1)