コード例 #1
0
ファイル: common_shapes.py プロジェクト: omardrwch/rlberry
def circle_shape(center, radius, n_points=50):
    shape = GeometricPrimitive("POLYGON")

    x0, y0 = center
    theta = np.linspace(0.0, 2 * np.pi, n_points)
    for tt in theta:
        xx = radius * np.cos(tt)
        yy = radius * np.sin(tt)
        shape.add_vertex((x0 + xx, y0 + yy))

    return shape
コード例 #2
0
ファイル: pball.py プロジェクト: antoine-moulin/rlberry
 def _get_ball_shape(self, xcenter, radius):
     shape = GeometricPrimitive("POLYGON")
     n_points = 200
     theta_vals = np.linspace(0.0, 2 * np.pi, n_points)
     for theta in theta_vals:
         pp = np.array([2.0 * np.cos(theta), 2.0 * np.sin(theta)])
         pp = xcenter + radius * projection_to_pball(pp, self.p)
         # project to the main ball after translation
         pp = projection_to_pball(pp, self.p)
         shape.add_vertex((pp[0], pp[1]))
     return shape
コード例 #3
0
ファイル: twinrooms.py プロジェクト: omardrwch/rlberry
    def get_background(self):
        """
        Returne a scene (list of shapes) representing the background
        """
        bg = Scene()

        # wall
        eps = self.wall_eps
        shape = GeometricPrimitive("POLYGON")
        shape.set_color((0.25, 0.25, 0.25))
        shape.add_vertex((1 - eps, 0))
        shape.add_vertex((1 - eps, 1))
        shape.add_vertex((1 + eps, 1))
        shape.add_vertex((1 + eps, 0))
        bg.add_shape(shape)

        # rewards
        for (x, y) in [
            self.base_reward_pos,
            self.base_reward_pos + np.array([1.0, 0.0]),
        ]:
            reward = circle_shape((x, y), 0.1, n_points=50)
            reward.type = "POLYGON"
            reward.set_color((0.0, 0.5, 0.0))
            bg.add_shape(reward)

        return bg
コード例 #4
0
ファイル: acrobot.py プロジェクト: lulica/rlberry
    def get_scene(self, state):
        scene = Scene()

        p0 = (0.0, 0.0)

        p1 = (self.LINK_LENGTH_1 * np.sin(state[0]),
              -self.LINK_LENGTH_1 * np.cos(state[0]))
        p2 = (p1[0] + self.LINK_LENGTH_2 * np.sin(state[0] + state[1]),
              p1[1] - self.LINK_LENGTH_2 * np.cos(state[0] + state[1]))

        link1 = bar_shape(p0, p1, 0.1)
        link1.set_color((255 / 255, 140 / 255, 0 / 255))

        link2 = bar_shape(p1, p2, 0.1)
        link2.set_color((210 / 255, 105 / 255, 30 / 255))

        joint1 = circle_shape(p0, 0.075)
        joint1.set_color((255 / 255, 215 / 255, 0 / 255))

        joint2 = circle_shape(p1, 0.075)
        joint2.set_color((255 / 255, 215 / 255, 0 / 255))

        goal_line = GeometricPrimitive("LINES")
        goal_line.add_vertex((-5, 1))
        goal_line.add_vertex((5, 1))

        scene.add_shape(link1)
        scene.add_shape(link2)
        scene.add_shape(joint1)
        scene.add_shape(joint2)
        scene.add_shape(goal_line)

        return scene
コード例 #5
0
    def get_scene(self, state):
        scene = Scene()

        agent = GeometricPrimitive("QUADS")
        agent.set_color((0.0, 0.0, 0.0))
        size = 0.025
        x = state[0]
        y = self._height(x)
        agent.add_vertex((x - size, y - size))
        agent.add_vertex((x + size, y - size))
        agent.add_vertex((x + size, y + size))
        agent.add_vertex((x - size, y + size))

        scene.add_shape(agent)
        return scene
コード例 #6
0
ファイル: common_shapes.py プロジェクト: omardrwch/rlberry
def bar_shape(p0, p1, width):
    shape = GeometricPrimitive("QUADS")

    x0, y0 = p0
    x1, y1 = p1

    direction = np.array([x1 - x0, y1 - y0])
    norm = np.sqrt((direction * direction).sum())
    direction = direction / norm

    # get vector perpendicular to direction
    u_vec = np.zeros(2)
    u_vec[0] = -direction[1]
    u_vec[1] = direction[0]

    u_vec = u_vec * width / 2

    shape.add_vertex((x0 + u_vec[0], y0 + u_vec[1]))
    shape.add_vertex((x0 - u_vec[0], y0 - u_vec[1]))
    shape.add_vertex((x1 - u_vec[0], y1 - u_vec[1]))
    shape.add_vertex((x1 + u_vec[0], y1 + u_vec[1]))
    return shape
コード例 #7
0
    def get_background(self):
        bg = Scene()
        mountain = GeometricPrimitive("TRIANGLE_FAN")
        flag = GeometricPrimitive("TRIANGLES")
        mountain.set_color((0.6, 0.3, 0.0))
        flag.set_color((0.0, 0.5, 0.0))

        # Mountain
        mountain.add_vertex((-0.3, -1.0))
        mountain.add_vertex((0.6, -1.0))

        n_points = 50
        obs_range = self.observation_space.high[
            0] - self.observation_space.low[0]
        eps = obs_range / (n_points - 1)
        for ii in reversed(range(n_points)):
            x = self.observation_space.low[0] + ii * eps
            y = self._height(x)
            mountain.add_vertex((x, y))
        mountain.add_vertex((-1.2, -1.0))

        # Flag
        goal_x = self.goal_position
        goal_y = self._height(goal_x)
        flag.add_vertex((goal_x, goal_y))
        flag.add_vertex((goal_x + 0.025, goal_y + 0.075))
        flag.add_vertex((goal_x - 0.025, goal_y + 0.075))

        bg.add_shape(mountain)
        bg.add_shape(flag)

        return bg
コード例 #8
0
ファイル: gridworld.py プロジェクト: lulica/rlberry
    def get_background(self):
        """
        Returne a scene (list of shapes) representing the background
        """
        bg = Scene()

        # walls
        for wall in self.walls:
            y, x = wall
            shape = GeometricPrimitive("POLYGON")
            shape.set_color((0.25, 0.25, 0.25))
            shape.add_vertex((x, y))
            shape.add_vertex((x + 1, y))
            shape.add_vertex((x + 1, y + 1))
            shape.add_vertex((x, y + 1))
            bg.add_shape(shape)

        # rewards
        for (y, x) in self.reward_at:
            flag = GeometricPrimitive("POLYGON")
            rwd = self.reward_at[(y, x)]
            if rwd > 0:
                flag.set_color((0.0, 0.5, 0.0))
            if rwd < 0:
                flag.set_color((0.5, 0.0, 0.0))

            x += 0.5
            y += 0.25
            flag.add_vertex((x, y))
            flag.add_vertex((x + 0.25, y + 0.5))
            flag.add_vertex((x - 0.25, y + 0.5))
            bg.add_shape(flag)

        return bg
コード例 #9
0
    def get_background(self):
        """
        Returne a scene (list of shapes) representing the background
        """
        bg = Scene()
        colors = [(0.8, 0.8, 0.8), (0.9, 0.9, 0.9)]
        for ii in range(self.L):
            shape = GeometricPrimitive("QUADS")
            shape.add_vertex((ii, 0))
            shape.add_vertex((ii + 1, 0))
            shape.add_vertex((ii + 1, 1))
            shape.add_vertex((ii, 1))
            shape.set_color(colors[ii % 2])
            bg.add_shape(shape)

        flag = GeometricPrimitive("TRIANGLES")
        flag.set_color((0.0, 0.5, 0.0))
        x = self.L - 0.5
        y = 0.25
        flag.add_vertex((x, y))
        flag.add_vertex((x + 0.25, y + 0.5))
        flag.add_vertex((x - 0.25, y + 0.5))
        bg.add_shape(flag)

        return bg
コード例 #10
0
    def get_scene(self, state):
        """
        Return scene (list of shapes) representing a given state
        """
        scene = Scene()

        agent = GeometricPrimitive("QUADS")
        agent.set_color((0.75, 0.0, 0.5))

        size = 0.25
        x = state + 0.5
        y = 0.5

        agent.add_vertex((x - size / 4.0, y - size))
        agent.add_vertex((x + size / 4.0, y - size))
        agent.add_vertex((x + size / 4.0, y + size))
        agent.add_vertex((x - size / 4.0, y + size))

        agent.add_vertex((x - size, y - size / 4.0))
        agent.add_vertex((x + size, y - size / 4.0))
        agent.add_vertex((x + size, y + size / 4.0))
        agent.add_vertex((x - size, y + size / 4.0))

        scene.add_shape(agent)
        return scene