Python gym.envs.classic_control.rendering.make_polyline() Examples
The following are 8
code examples of gym.envs.classic_control.rendering.make_polyline().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gym.envs.classic_control.rendering
, or try the search function
.
Example #1
Source File: mountain_car.py From DRL_DeliveryDuel with MIT License | 4 votes |
def render(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width/world_width carwidth=40 carheight=20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs-self.min_position)*scale, ys*scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l,r,t,b = -carwidth/2, carwidth/2, carheight, 0 car = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight/2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth/4,clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight/2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth/4,clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position-self.min_position)*scale flagy1 = self._height(self.goal_position)*scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2-10), (flagx+25, flagy2-5)]) flag.set_color(.8,.8,0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos-self.min_position)*scale, self._height(pos)*scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array = mode=='rgb_array')
Example #2
Source File: continuous_mountain_car.py From DRL_DeliveryDuel with MIT License | 4 votes |
def render(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width/world_width carwidth=40 carheight=20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs-self.min_position)*scale, ys*scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l,r,t,b = -carwidth/2, carwidth/2, carheight, 0 car = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight/2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth/4,clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight/2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth/4,clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position-self.min_position)*scale flagy1 = self._height(self.goal_position)*scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2-10), (flagx+25, flagy2-5)]) flag.set_color(.8,.8,0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos-self.min_position)*scale, self._height(pos)*scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array = mode=='rgb_array')
Example #3
Source File: mountain_car.py From ia-course with MIT License | 4 votes |
def render(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width/world_width carwidth=40 carheight=20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs-self.min_position)*scale, ys*scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l,r,t,b = -carwidth/2, carwidth/2, carheight, 0 car = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight/2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth/4,clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight/2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth/4,clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position-self.min_position)*scale flagy1 = self._height(self.goal_position)*scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2-10), (flagx+25, flagy2-5)]) flag.set_color(.8,.8,0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos-self.min_position)*scale, self._height(pos)*scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array = mode=='rgb_array')
Example #4
Source File: continuous_mountain_car.py From ia-course with MIT License | 4 votes |
def render(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width/world_width carwidth=40 carheight=20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs-self.min_position)*scale, ys*scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l,r,t,b = -carwidth/2, carwidth/2, carheight, 0 car = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight/2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth/4,clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight/2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth/4,clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position-self.min_position)*scale flagy1 = self._height(self.goal_position)*scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2-10), (flagx+25, flagy2-5)]) flag.set_color(.8,.8,0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos-self.min_position)*scale, self._height(pos)*scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array = mode=='rgb_array')
Example #5
Source File: mountain_car.py From memory-augmented-self-play with MIT License | 4 votes |
def display(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width / world_width carwidth = 40 carheight = 20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs - self.min_position) * scale, ys * scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l, r, t, b = -carwidth / 2, carwidth / 2, carheight, 0 car = rendering.FilledPolygon([(l, b), (l, t), (r, t), (r, b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight / 2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth / 4, clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight / 2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth / 4, clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position - self.min_position) * scale flagy1 = self._height(self.goal_position) * scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2 - 10), (flagx + 25, flagy2 - 5)]) flag.set_color(.8, .8, 0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos - self.min_position) * scale, self._height(pos) * scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array=mode == 'rgb_array')
Example #6
Source File: mountain_car.py From DQN-DDPG_Stock_Trading with MIT License | 4 votes |
def render(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width/world_width carwidth=40 carheight=20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs-self.min_position)*scale, ys*scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l,r,t,b = -carwidth/2, carwidth/2, carheight, 0 car = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight/2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth/4,clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight/2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth/4,clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position-self.min_position)*scale flagy1 = self._height(self.goal_position)*scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2-10), (flagx+25, flagy2-5)]) flag.set_color(.8,.8,0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos-self.min_position)*scale, self._height(pos)*scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array = mode=='rgb_array')
Example #7
Source File: continuous_mountain_car.py From DQN-DDPG_Stock_Trading with MIT License | 4 votes |
def render(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width/world_width carwidth=40 carheight=20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs-self.min_position)*scale, ys*scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l,r,t,b = -carwidth/2, carwidth/2, carheight, 0 car = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight/2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth/4,clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight/2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth/4,clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position-self.min_position)*scale flagy1 = self._height(self.goal_position)*scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2-10), (flagx+25, flagy2-5)]) flag.set_color(.8,.8,0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos-self.min_position)*scale, self._height(pos)*scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array = mode=='rgb_array')
Example #8
Source File: continuous_mountain_car.py From Hierarchical-Actor-Critic-HAC-PyTorch with MIT License | 4 votes |
def render(self, mode='human'): screen_width = 600 screen_height = 400 world_width = self.max_position - self.min_position scale = screen_width/world_width carwidth=40 carheight=20 if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.Viewer(screen_width, screen_height) xs = np.linspace(self.min_position, self.max_position, 100) ys = self._height(xs) xys = list(zip((xs-self.min_position)*scale, ys*scale)) self.track = rendering.make_polyline(xys) self.track.set_linewidth(4) self.viewer.add_geom(self.track) clearance = 10 l,r,t,b = -carwidth/2, carwidth/2, carheight, 0 car = rendering.FilledPolygon([(l,b), (l,t), (r,t), (r,b)]) car.add_attr(rendering.Transform(translation=(0, clearance))) self.cartrans = rendering.Transform() car.add_attr(self.cartrans) self.viewer.add_geom(car) frontwheel = rendering.make_circle(carheight/2.5) frontwheel.set_color(.5, .5, .5) frontwheel.add_attr(rendering.Transform(translation=(carwidth/4,clearance))) frontwheel.add_attr(self.cartrans) self.viewer.add_geom(frontwheel) backwheel = rendering.make_circle(carheight/2.5) backwheel.add_attr(rendering.Transform(translation=(-carwidth/4,clearance))) backwheel.add_attr(self.cartrans) backwheel.set_color(.5, .5, .5) self.viewer.add_geom(backwheel) flagx = (self.goal_position-self.min_position)*scale flagy1 = self._height(self.goal_position)*scale flagy2 = flagy1 + 50 flagpole = rendering.Line((flagx, flagy1), (flagx, flagy2)) self.viewer.add_geom(flagpole) flag = rendering.FilledPolygon([(flagx, flagy2), (flagx, flagy2-10), (flagx+25, flagy2-5)]) flag.set_color(.8,.8,0) self.viewer.add_geom(flag) pos = self.state[0] self.cartrans.set_translation((pos-self.min_position)*scale, self._height(pos)*scale) self.cartrans.set_rotation(math.cos(3 * pos)) return self.viewer.render(return_rgb_array = mode=='rgb_array')