2
\$\begingroup\$

How can I improve this code? It renders a ML env with openAI gym and matplotlib. I am new to coding so not sure if my variables or format or any lines can be improved.

def _render(self, obs):
    """Renders the environment.
    """

    ball_loc = obs[1]
    x, y = self.circle.center

    new_y = math.tan(-math.radians(obs[3])) * (ball_loc - self.target_location)

    self.circle.center = (ball_loc, 10 + new_y + 1)

    t_start = self.ax.transData
    coords = t_start.transform([self.target_location, 10])
    t = mpl.transforms.Affine2D().rotate_deg_around(coords[0], coords[1], -obs[3])
    t_end = t_start + t
    self.rect.set_transform(t_end)

    self.fig.canvas.draw()
    plt.pause(0.05)
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Hi! Welcome to code review, Please add enough details about your code in the question body, anything that will be useful to people who'd want to review your code \$\endgroup\$ – Aryan Parekh Nov 2 '20 at 9:41
  • 1
    \$\begingroup\$ We need to see more of the code - at the very least, your import statements; but ideally the entire program. \$\endgroup\$ – Reinderien Nov 3 '20 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.