def render(self, img): tri_fn = rendering.point_in_triangle( (0.12, 0.19), (0.87, 0.50), (0.12, 0.81), ) # Rotate the agent based on its direction tri_fn = rendering.rotate_fn(tri_fn, cx=0.5, cy=0.5, theta=0.5 * math.pi * self.dir) c = minigrid.COLORS[self.team.color] rendering.fill_coords(img, tri_fn, c) if self.is_holding: c = minigrid.COLORS[self._holding.team.color] # Vertical quad post = minigrid.point_in_rect(0.20, 0.25, 0.20, 0.45) post = minigrid.rotate_fn(post, cx=0.5, cy=0.5, theta=0.5 * np.pi * (self.dir)) minigrid.fill_coords(img, post, c) flag = minigrid.point_in_triangle( (0.20, 0.20), (0.20, 0.10), (0.40, 0.15), ) flag = minigrid.rotate_fn(flag, cx=0.5, cy=0.5, theta=0.5 * np.pi * (self.dir)) minigrid.fill_coords(img, flag, c)
def render_tile(cls, obj, highlight=False, tile_size=TILE_PIXELS, subdivs=3): if obj is None: key = ( tile_size, highlight, ) else: key = (tile_size, highlight, *obj.encode()) if key in cls.tile_cache: img = cls.tile_cache[key] else: img = np.zeros( shape=(tile_size * subdivs, tile_size * subdivs, 3), dtype=np.uint8 ) # Draw the grid lines (top and left edges) fill_coords(img, point_in_rect(0, 0.031, 0, 1), (100, 100, 100)) fill_coords(img, point_in_rect(0, 1, 0, 0.031), (100, 100, 100)) if obj != None: obj.render(img) if highlight: highlight_img(img) img = downsample(img, subdivs) cls.tile_cache[key] = img return img
def render(self, img): tri_fn = point_in_triangle( (0.12, 0.19), (0.87, 0.50), (0.12, 0.81), ) tri_fn = rotate_fn(tri_fn, cx=0.5, cy=0.5, theta=0.5 * np.pi * (self.dir)) fill_coords(img, tri_fn, COLORS[self.color])
def render(self, img): tri_fn = rendering.point_in_triangle( (0.12, 0.19), (0.87, 0.50), (0.12, 0.81), ) # Rotate the agent based on its direction tri_fn = rendering.rotate_fn( tri_fn, cx=0.5, cy=0.5, theta=0.5 * math.pi * self.dir) color = AGENT_COLOURS[self.agent_id] rendering.fill_coords(img, tri_fn, color)
def render_tile( cls, obj, highlight=None, tile_size=minigrid.TILE_PIXELS, subdivs=3, cell_type=None, ): """Render a tile and cache the result.""" # Hash map lookup key for the cache if isinstance(highlight, list): key = (tuple(highlight), tile_size) else: key = (highlight, tile_size) key = obj.encode() + key if obj else key if key in cls.tile_cache: return cls.tile_cache[key] img = np.zeros(shape=(tile_size * subdivs, tile_size * subdivs, 3), dtype=np.uint8) # Draw the grid lines (top and left edges) rendering.fill_coords(img, rendering.point_in_rect(0, 0.031, 0, 1), (100, 100, 100)) rendering.fill_coords(img, rendering.point_in_rect(0, 1, 0, 0.031), (100, 100, 100)) if obj is not None and obj.type != "agent": obj.render(img) # Highlight the cell if needed (do not highlight walls) if highlight and not (cell_type is not None and cell_type == "wall"): if isinstance(highlight, list): for a, agent_highlight in enumerate(highlight): if agent_highlight: rendering.highlight_img(img, color=AGENT_COLOURS[a]) else: # Default highlighting for agent's partially observed views rendering.highlight_img(img) # Render agents after highlight to avoid highlighting agent triangle (the # combination of colours makes it difficult to ID agent) if obj is not None and obj.type == "agent": obj.render(img) # Downsample the image to perform supersampling/anti-aliasing img = rendering.downsample(img, subdivs) # Cache the rendered tile cls.tile_cache[key] = img return img
def render(self, img): c = COLORS[self.color] # Vertical quad fill_coords(img, point_in_rect(0.50, 0.63, 0.31, 0.88), c) # Teeth fill_coords(img, point_in_rect(0.38, 0.50, 0.59, 0.66), c) fill_coords(img, point_in_rect(0.38, 0.50, 0.81, 0.88), c) # Ring fill_coords(img, point_in_circle(cx=0.56, cy=0.28, r=0.190), c) fill_coords(img, point_in_circle(cx=0.56, cy=0.28, r=0.064), (0, 0, 0))
def render(self, img): c = (255, 128, 0) # Background color fill_coords(img, point_in_rect(0, 1, 0, 1), c) # Little waves for i in range(3): ylo = 0.3 + 0.2 * i yhi = 0.4 + 0.2 * i fill_coords(img, point_in_line(0.1, ylo, 0.3, yhi, r=0.03), (0, 0, 0)) fill_coords(img, point_in_line(0.3, yhi, 0.5, ylo, r=0.03), (0, 0, 0)) fill_coords(img, point_in_line(0.5, ylo, 0.7, yhi, r=0.03), (0, 0, 0)) fill_coords(img, point_in_line(0.7, yhi, 0.9, ylo, r=0.03), (0, 0, 0))
def render(self, img): c = COLORS[self.color] # Outline fill_coords(img, point_in_rect(0.12, 0.88, 0.12, 0.88), c) fill_coords(img, point_in_rect(0.18, 0.82, 0.18, 0.82), (0, 0, 0)) # Horizontal slit fill_coords(img, point_in_rect(0.16, 0.84, 0.47, 0.53), c)
def render(self, img): c = COLORS[self.color] if self.state == self.states.open: fill_coords(img, point_in_rect(0.88, 1.00, 0.00, 1.00), c) fill_coords(img, point_in_rect(0.92, 0.96, 0.04, 0.96), (0, 0, 0)) return # Door frame and door if self.state == self.states.locked: fill_coords(img, point_in_rect(0.00, 1.00, 0.00, 1.00), c) fill_coords(img, point_in_rect(0.06, 0.94, 0.06, 0.94), 0.45 * np.array(c)) # Draw key slot fill_coords(img, point_in_rect(0.52, 0.75, 0.50, 0.56), c) else: fill_coords(img, point_in_rect(0.00, 1.00, 0.00, 1.00), c) fill_coords(img, point_in_rect(0.04, 0.96, 0.04, 0.96), (0, 0, 0)) fill_coords(img, point_in_rect(0.08, 0.92, 0.08, 0.92), c) fill_coords(img, point_in_rect(0.12, 0.88, 0.12, 0.88), (0, 0, 0)) # Draw door handle fill_coords(img, point_in_circle(cx=0.75, cy=0.50, r=0.08), c)
def render(self, img): fill_coords(img, point_in_circle(0.5, 0.5, 0.31), COLORS[self.color])
def render(self, img): fill_coords(img, point_in_rect(0, 1, 0, 1), COLORS[self.color])
def render(self, img): if self.active: fill_coords(img, point_in_rect(0, 1, 0, 1), COLORS[self.color]) else: fill_coords(img, point_in_rect(0, 1, 0, 1), COLORS['black'])