-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)''' |