Skip to content

Commit

Permalink
visualisons !
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsalm committed May 12, 2024
1 parent 533b270 commit b0e2fcf
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 3 deletions.
Binary file added __pycache__/visualize.cpython-312.pyc
Binary file not shown.
14 changes: 11 additions & 3 deletions env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from gymnasium import spaces
import equations
import visualize as vis

# flake8: noqa

Expand Down Expand Up @@ -85,7 +86,14 @@ def reward(self, state, action):

return r

env = Env()
# test the environment and visualize the results
'''env = Env()
print(env.reset())
for i in range(100):
print(env.step([0., -0.2, 0., 0.]))
indices = [[0, 10000]]
for i in range(200):
state, r, ok = env.step([0.2, 0.2, 0.2, 0.2])
indices.append([state[0], state[1]])
print(indices)
vis.visualize(indices)'''


Binary file added spacecraft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions visualize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import pygame
import sys

# flake8: noqa

# Initialisation de Pygame
pygame.init()

# Définition de la taille de la fenêtre
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Vaisseau suivant une droite")

# Couleurs
BROWN =(165, 80, 80)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
EARTH_BLUE = (0, 69, 240)
EARTH_GREEN = (0, 128, 0)

# Chargement de l'image du vaisseau
vaisseau_original = pygame.image.load("spacecraft.png")
vaisseau_original_rect = vaisseau_original.get_rect()
# Redimensionnement de l'image du vaisseau
vaisseau_width = 30
vaisseau_height = 20
vaisseau_image = pygame.transform.scale(vaisseau_original, (vaisseau_width, vaisseau_height))
vaisseau_rect = vaisseau_image.get_rect()

# Coordonnées du point sur la droite
point_x = 650
point_y = 300

def draw_circle():
pygame.draw.circle(screen, BROWN, (650, point_y), 15)

def draw_earth():
pygame.draw.rect(screen, EARTH_BLUE, (0, 0, screen_width, 30))
pygame.draw.rect(screen, EARTH_GREEN, (0, 0, screen_width, 15))

# Fonction pour dessiner la droite
def draw_line():
pygame.draw.line(screen, WHITE, (0, point_y), (screen_width, point_y))

# Fonction pour mettre à jour la position du vaisseau
def update_vaisseau(x, y):
vaisseau_rect.center = (point_x - y, point_y + x)

def dot(x, y):
pygame.draw.circle(screen, RED, (point_x - y, point_y + x), 2)

# Boucle principale
def visualize(indices):

running = True
cruise = True
while running:
if cruise:
for i in range(len(indices)):

if i == len(indices) - 1:
cruise = False

# Effacer l'écran
screen.fill(BLACK)

# Dessiner la droite
draw_earth()
draw_line()
draw_circle()

# Mettre à jour la position du vaisseau
update_vaisseau(indices[i][0]/10000000, indices[i][1]*6/100) # Mettez vos coordonnées x et y ici

# Afficher le vaisseau
screen.blit(vaisseau_image, vaisseau_rect)

if i > 0:
for j in range(i-1):
dot(indices[j][0]/1000, indices[j][1]*6/100)

# Actualiser l'affichage
pygame.display.flip()

# Limiter le nombre d'images par seconde
pygame.time.Clock().tick(10)

for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:

mouse_x, mouse_y = pygame.mouse.get_pos()
if 0 <= mouse_x <= screen_width and 0 <= mouse_y <= screen_height:
# Si le clic est à l'intérieur de la fenêtre, fermer la fenêtre
running = False

# Quitter Pygame
pygame.quit()
sys.exit()


'''indices = [[0, 10000 - i*100] for i in range(50)]
visualize(indices)'''

0 comments on commit b0e2fcf

Please sign in to comment.